DataSet.threshold(value=None, scalars=None, invert=False, continuous=False, preference='cell', all_scalars=False, progress_bar=False, component_mode='all', component=0)#

Apply a vtkThreshold filter to the input dataset.

This filter will apply a vtkThreshold filter to the input dataset and return the resulting object. This extracts cells where the scalar value in each cell satisfies the threshold criterion. If scalars is None, the input’s active scalars array is used.


Thresholding is inherently a cell operation, even though it can use associated point data for determining whether to keep a cell. In other words, whether or not a given point is included after thresholding depends on whether that point is part of a cell that is kept after thresholding.

valuefloat or sequence, optional

Single value or (min, max) to be used for the data threshold. If a sequence, then length must be 2. If no value is specified, the non-NaN data range will be used to remove any NaN values.

scalarsstr, optional

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

invertbool, optional

If value is a single value, when invert is True cells are kept when their values are below parameter "value". When invert is False cells are kept when their value is above the threshold "value". 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'.

all_scalarsbool, optional

If using scalars from point data, all points in a cell must satisfy the threshold when this value is True. When False, any point of the cell with a scalar value satisfying the threshold criterion will extract the cell. Has no effect when using cell data.

progress_barbool, optional

Display a progress bar to indicate progress.

component_mode{‘selected’, ‘all’, ‘any’}

The method to satisfy the criteria for the threshold of multicomponent scalars. ‘selected’ (default) uses only the component. ‘all’ requires all components to meet criteria. ‘any’ is when any component satisfies the criteria.


When using component_mode='selected', this sets which component to threshold on. Default is 0.


Dataset containing geometry that meets the threshold requirements.


>>> import pyvista
>>> import numpy as np
>>> volume = np.zeros([10, 10, 10])
>>> volume[:3] = 1
>>> vol = pyvista.wrap(volume)
>>> threshed = vol.threshold(0.1)
>>> threshed  
UnstructuredGrid (0x7f00f9983fa0)
  N Cells:      243
  N Points:     400
  X Bounds:     0.000e+00, 3.000e+00
  Y Bounds:     0.000e+00, 9.000e+00
  Z Bounds:     0.000e+00, 9.000e+00
  N Arrays:     1

Apply the threshold filter to Perlin noise. First generate the structured grid.

>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0],
...                                dim=(20, 20, 20))
>>> grid.plot(cmap='gist_earth_r', show_scalar_bar=True, show_edges=False)

Next, apply the threshold.

>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0],
...                                dim=(20, 20, 20))
>>> threshed = grid.threshold(value=0.02)
>>> threshed.plot(cmap='gist_earth_r', show_scalar_bar=False, show_edges=True)

See Using Common Filters for more examples using this filter.