threshold_percent

UniformGridFilters.threshold_percent(percent=0.5, scalars=None, invert=False, continuous=False, preference='cell', progress_bar=False)

Threshold the dataset by a percentage of its range on the active scalars array.

Parameters
percentfloat or tuple(float), optional

The percentage (0,1) to threshold. If value is out of 0 to 1 range, then it will be divided by 100 and checked to be in that range.

scalarsstr, optional

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

invertbool, optional

When invert is True cells are kept when their values are below the percentage of the range. When invert is False, cells are kept when their value is above the percentage of the range. Default is False: yielding above the threshold "value".

continuousbool, optional

When True, the continuous interval [minimum cell scalar, maximum cell scalar] will be used to intersect the threshold bound, rather than the set of discrete scalar values from the vertices.

preferencestr, optional

When scalars is specified, this is the preferred array type to search for in the dataset. Must be either 'point' or 'cell'.

progress_barbool, optional

Display a progress bar to indicate progress.

Returns
pyvista.UnstructuredGrid

Dataset containing geometry that meets the threshold requirements.

Examples

Apply a 50% threshold filter.

>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (2, 2, 2), (0, 0, 0))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0],
...                                dim=(30, 30, 30))
>>> threshed = grid.threshold_percent(0.5)
>>> threshed.plot(cmap='gist_earth_r', show_scalar_bar=False, show_edges=True)
../../../_images/pyvista-UniformGridFilters-threshold_percent-1_00_00.png

Apply a 80% threshold filter.

>>> threshed = grid.threshold_percent(0.8)
>>> threshed.plot(cmap='gist_earth_r', show_scalar_bar=False, show_edges=True)
../../../_images/pyvista-UniformGridFilters-threshold_percent-1_01_00.png

See Using Common Filters for more examples using a similar filter.