pyvista_js.PolyData.contour#
- PolyData.contour(isosurfaces: int | list[float] = 10, scalars: ArrayLike | None = None, scalar_name: str | None = None) PolyData#
Generate contour lines at constant scalar values.
This filter extracts isolines from the mesh at specified scalar values using a marching triangles algorithm implemented in JavaScript. It mirrors the PyVista
contourfilter API.Note
The contour is computed in JavaScript at render time by applying the marching triangles algorithm to each triangle of the mesh, interpolating edge crossings at the specified iso-values.
vtk.jsdoes not supportvtkPolyDatainput forvtkContourFilter, so this filter is implemented as a custom JavaScript pass.- Parameters:
isosurfaces (int or list of float, optional) – Number of evenly spaced contours to generate, or a list of explicit scalar values at which to generate contours. Default is 10.
scalars (array-like, optional) – Scalar values per point to use for contouring. If not provided, uses the mesh’s existing
scalarsattribute. Must have length equal ton_points.scalar_name (str, optional) – Name for the scalar array in vtk.js. If not provided, uses the mesh’s existing
scalar_nameattribute or defaults to “scalars”.
- Returns:
A new mesh containing the contour lines.
- Return type:
- Raises:
ValueError – If no scalars are provided and the mesh has no scalar data, or if isosurfaces parameter is invalid.
Examples
>>> import pyvista_js as pv >>> sphere = pv.Sphere() >>> sphere_scalars = sphere.points[:, 2] >>> contours = sphere.contour(isosurfaces=5, scalars=sphere_scalars) >>> isinstance(contours, pv.PolyData) True
Generate contours at specific values:
>>> contours = sphere.contour(isosurfaces=[-0.5, 0.0, 0.5], scalars=sphere_scalars)
Render the contours:
>>> contours.plot()