DataSetFilters.clip_scalar

DataSetFilters.clip_scalar#

DataSetFilters.clip_scalar(
*,
scalars: str | None = None,
invert: bool = True,
value: float | VectorLikeFloat = 0.0,
inplace: bool = False,
progress_bar: bool = False,
both: bool = False,
) → _OutputDataSet | tuple[_OutputDataSet, _OutputDataSet][source]#

Clip a dataset by a scalar.

Changed in version 0.49: Points that a PolyData input keeps apart are no longer merged, unless it holds triangle strips.

Parameters:
scalarsstr, optional

Name of scalars to clip on. Defaults to currently active scalars.

invertbool, default: True

Flag on whether to flip/invert the clip. When True, only the mesh below value will be kept. When False, only values above value will be kept.

valuefloat | VectorLikeFloat, default: 0.0

Set the clipping value. Can also be set as a range of values. The range produces an output similar to an isovolume filter of ParaView.

inplacebool, default: False

Update mesh in-place. Only PolyData, PointSet and UnstructuredGrid inputs support this; any other input raises TypeError.

progress_barbool, default: False

Display a progress bar to indicate progress.

bothbool, default: False

If True, also returns the complementary clipped mesh.

Returns:
outputpyvista.DataSet | tuple[pyvista.DataSet, pyvista.DataSet]

Clipped dataset if both=False. If both=True then returns a tuple of both clipped datasets. A PolyData gives a PolyData and a PointSet gives a PointSet; every other dataset gives an UnstructuredGrid.

Notes#

This filter is not available on a MultiBlock. Use clip() or clip_box() for a composite, or apply this filter to each block with generic_filter().

Examples#

Download Python source code | Download Jupyter notebook

Remove the part of the mesh with sample_point_scalars above 100.

>>> import pyvista as pv
>>> from pyvista import examples
>>> dataset = examples.load_hexbeam()
>>> clipped = dataset.clip_scalar(scalars='sample_point_scalars', value=100)
>>> clipped.plot()
../../../_images/pyvista-DataSetFilters-clip_scalar-0fb1925322ef98b1_00_00.png

Get clipped meshes corresponding to the portions of the mesh above and below 100.

>>> import pyvista as pv
>>> from pyvista import examples
>>> dataset = examples.load_hexbeam()
>>> _below, _above = dataset.clip_scalar(
...     scalars='sample_point_scalars', value=100, both=True
... )

Remove the part of the mesh with sample_point_scalars below 100.

>>> import pyvista as pv
>>> from pyvista import examples
>>> dataset = examples.load_hexbeam()
>>> clipped = dataset.clip_scalar(
...     scalars='sample_point_scalars', value=100, invert=False
... )
>>> clipped.plot()
../../../_images/pyvista-DataSetFilters-clip_scalar-0fb1925322ef98b1_01_00.png

Clip the part of the mesh with sample_point_scalars between 200 and 250.

>>> import pyvista as pv
>>> from pyvista import examples
>>> dataset = examples.load_hexbeam()
>>> clipped = dataset.clip_scalar(
...     scalars='sample_point_scalars', value=(200, 250)
... )
>>> clipped.plot()
../../../_images/pyvista-DataSetFilters-clip_scalar-0fb1925322ef98b1_02_00.png