contour#
- PolyDataFilters.contour(isosurfaces=10, scalars=None, compute_normals=False, compute_gradients=False, compute_scalars=True, rng=None, preference='point', method='contour', progress_bar=False)#
Contour an input self by an array.
isosurfaces
can be an integer specifying the number of isosurfaces in the data range or a sequence of values for explicitly setting the isosurfaces.- Parameters
- isosurfaces
int
or sequence,optional
Number of isosurfaces to compute across valid data range or a sequence of float values to explicitly use as the isosurfaces.
- scalars
str
,numpy.ndarray
,optional
Name or array of scalars to threshold on. Defaults to currently active scalars.
- compute_normalsbool,
optional
Compute normals for the dataset.
- compute_gradientsbool,
optional
Compute gradients for the dataset.
- compute_scalarsbool,
optional
Preserves the scalar values that are being contoured.
- rng
tuple
(float
),optional
If an integer number of isosurfaces is specified, this is the range over which to generate contours. Default is the scalars array’s full data range.
- preference
str
,optional
When
scalars
is specified, this is the preferred array type to search for in the dataset. Must be either'point'
or'cell'
.- method
str
,optional
Specify to choose which vtk filter is used to create the contour. Must be one of
'contour'
,'marching_cubes'
and'flying_edges'
. Defaults to'contour'
.- progress_barbool,
optional
Display a progress bar to indicate progress.
- isosurfaces
- Returns
pyvista.PolyData
Contoured surface.
Examples
Generate contours for the random hills dataset.
>>> from pyvista import examples >>> hills = examples.load_random_hills() >>> contours = hills.contour() >>> contours.plot(line_width=5)
Generate the surface of a mobius strip using flying edges.
>>> import pyvista as pv >>> a = 0.4 >>> b = 0.1 >>> def f(x, y, z): ... xx = x*x ... yy = y*y ... zz = z*z ... xyz = x*y*z ... xx_yy = xx + yy ... a_xx = a*xx ... b_yy = b*yy ... return ( ... (xx_yy + 1) * (a_xx + b_yy) ... + zz * (b * xx + a * yy) - 2 * (a - b) * xyz ... - a * b * xx_yy ... )**2 - 4 * (xx + yy) * (a_xx + b_yy - xyz * (a - b))**2 >>> n = 100 >>> x_min, y_min, z_min = -1.35, -1.7, -0.65 >>> grid = pv.UniformGrid( ... dims=(n, n, n), ... spacing=(abs(x_min)/n*2, abs(y_min)/n*2, abs(z_min)/n*2), ... origin=(x_min, y_min, z_min), ... ) >>> x, y, z = grid.points.T >>> values = f(x, y, z) >>> out = grid.contour( ... 1, scalars=values, rng=[0, 0], method='flying_edges' ... ) >>> out.plot(color='tan', smooth_shading=True)
See Using Common Filters or Marching Cubes for more examples using this filter.