pyvista.DataObjectFilters.slice

pyvista.DataObjectFilters.slice#

DataObjectFilters.slice(
normal: VectorLike[float] | _NormalsLiteral | None = None,
origin: VectorLike[float] | None = None,
generate_triangles: bool = False,
contour: bool = False,
progress_bar: bool = False,
plane: PolyData | None = None,
)[source]#

Slice a dataset by a plane at the specified origin and normal vector orientation.

The origin and normal may be set explicitly or implicitly using a Plane().

If no parameters are given, the slice will occur in the center of the dataset along the x-axis.

Parameters:
normalVectorLike[float] | str, optional

Length-3 vector for the normal vector direction. Can also be specified as a string conventional direction such as 'x' for (1, 0, 0) or '-x' for (-1, 0, 0), etc. The 'x' direction is used by default.

originsequence[float], optional

The center (x, y, z) coordinate of the plane on which the slice occurs. The default is the center of the dataset.

generate_trianglesbool, default: False

If this is enabled (False by default), the output will be triangles. Otherwise the output will be the intersection polygons.

contourbool, default: False

If True, apply a contour filter after slicing.

progress_barbool, default: False

Display a progress bar to indicate progress.

planePolyData, optional

Plane() mesh to use for slicing. Use this as an alternative to setting origin and normal. The mean of the plane’s normal vectors is used for the normal parameter and the mean of the plane’s points is used for the origin parameter.

Added in version 0.47.

Returns:
pyvista.PolyData

Sliced dataset.

Examples

Slice the surface of a sphere.

>>> import pyvista as pv
>>> sphere = pv.Sphere()
>>> slice_x = sphere.slice(normal='x')
>>> slice_y = sphere.slice(normal='y')
>>> slice_z = sphere.slice(normal='z')
>>> slices = slice_x + slice_y + slice_z
>>> slices.plot(line_width=5)
../../../_images/pyvista-DataObjectFilters-slice-11d08d42269e691e_00_00.png

See Slicing for more examples using this filter.