DataObjectFilters.slice_along_axis

DataObjectFilters.slice_along_axis#

DataObjectFilters.slice_along_axis(
n: int = 5,
axis: Literal['x', 'y', 'z', 0, 1, 2] = 'x',
*,
tolerance: float | None = None,
generate_triangles: bool = False,
contour: bool = False,
bounds: VectorLikeFloat | None = None,
center: VectorLikeFloat | None = None,
progress_bar: bool = False,
) → MultiBlock[source]#

Create many slices of the input dataset along a specified axis.

Parameters:
nint, default: 5

The number of slices to create.

axisstr | int, default: ‘x’

The axis to generate the slices along. Perpendicular to the slices. Can be string name ('x', 'y', or 'z') or axis index (0, 1, or 2).

tolerancefloat, optional

The tolerance to the edge of the dataset bounds to create the slices. The n slices are placed equidistantly with an absolute padding of tolerance inside each side of the bounds along the specified axis. Defaults to 1% of the bounds along the specified axis.

generate_trianglesbool, default: False

When True, the output will be triangles. Otherwise the output will be the intersection polygons.

Note

PyVista’s default differs from vtkCutter (which defaults to True). The polygon path is ~5x slower on UnstructuredGrids. Pass generate_triangles=True for the fast path. See slice_implicit() for details.

contourbool, default: False

If True, apply a contour filter after slicing.

boundsVectorLikeFloat, optional

A 6-length sequence overriding the bounds of the mesh. The bounds along the specified axis define the extent where slices are taken.

centerVectorLikeFloat, optional

A 3-length sequence specifying the position of the line along which slices are taken. Defaults to the center of the mesh.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.MultiBlock

Sliced dataset, with one PolyData block per slice. A MultiBlock gives one such MultiBlock per block, nested blocks included.

Notes#

A PointSet has no cells to slice, so slicing one raises PointSetDimensionReductionError, whether it is sliced directly or as a block of a MultiBlock.

Changed in version 0.50: A PointSet block raises instead of giving an empty block.

Examples#

Download Python source code | Download Jupyter notebook

Slice the random hills dataset in the X direction.

>>> from pyvista import examples
>>> hills = examples.load_random_hills()
>>> slices = hills.slice_along_axis(n=10)
>>> slices.plot(line_width=5)
../../../_images/pyvista-DataObjectFilters-slice_along_axis-26c4eff95cc68f23_00_00.png

Slice the random hills dataset in the Z direction.

>>> from pyvista import examples
>>> hills = examples.load_random_hills()
>>> slices = hills.slice_along_axis(n=10, axis='z')
>>> slices.plot(line_width=5)
../../../_images/pyvista-DataObjectFilters-slice_along_axis-26c4eff95cc68f23_01_00.png

See Also#

slice
slice_implicit
slice_orthogonal
slice_along_line
slice_index()