pyvista_wasm.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. The contour is computed at render time as a manual implementation becausevtkContourFilteris not registered with thevtkDeserializerin VTK.wasm’s rendering-mode binary.- 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.wasm. 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_wasm 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()