Easier Pythonic interface to VTK for 3D scientific data visualization and mesh analysis
—
PyVista provides comprehensive data structure classes that wrap VTK objects with Pythonic interfaces for representing different types of 3D spatial data.
Represents surfaces, lines, and vertices. The most common mesh type for surface visualization and CAD data.
class PolyData:
"""
Polygonal data consisting of vertices, lines, polygons, and triangle strips.
Attributes:
points: np.ndarray - 3D coordinates of vertices
faces: np.ndarray - Connectivity information for polygons
lines: np.ndarray - Connectivity for line segments
verts: np.ndarray - Connectivity for vertices
n_points: int - Number of points
n_cells: int - Number of cells
n_faces: int - Number of faces
bounds: tuple - Spatial extent (xmin, xmax, ymin, ymax, zmin, zmax)
"""
def __init__(self, var_inp=None, deep=False, **kwargs): ...
# Array access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...
# Basic operations
def copy(self, deep=True) -> 'PolyData': ...
def clean(self, **kwargs) -> 'PolyData': ...
def extract_surface(self, **kwargs) -> 'PolyData': ...
def triangulate(self, **kwargs) -> 'PolyData': ...Represents meshes with arbitrary cell types including tetrahedra, hexahedra, prisms, and pyramids.
class UnstructuredGrid:
"""
Unstructured grid with arbitrary cell types and connectivity.
Attributes:
points: np.ndarray - 3D coordinates of vertices
cells: CellArray - Cell connectivity information
celltypes: np.ndarray - VTK cell type for each cell
n_points: int - Number of points
n_cells: int - Number of cells
bounds: tuple - Spatial extent
"""
def __init__(self, var_inp=None, deep=False, **kwargs): ...
# Array access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...
# Grid operations
def extract_cells(self, ind: ArrayLike) -> 'UnstructuredGrid': ...
def remove_cells(self, ind: ArrayLike) -> 'UnstructuredGrid': ...
def explode(self, factor=0.1) -> 'UnstructuredGrid': ...Represents curvilinear grids with regular topology but irregular geometry.
class StructuredGrid:
"""
Structured grid with regular topology and arbitrary point coordinates.
Attributes:
points: np.ndarray - 3D coordinates arranged in grid structure
dimensions: tuple - Grid dimensions (ni, nj, nk)
n_points: int - Number of points
n_cells: int - Number of cells
bounds: tuple - Spatial extent
"""
def __init__(self, var_inp=None, deep=False, **kwargs): ...
# Array access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...
# Grid operations
def extract_subset(self, voi: tuple) -> 'StructuredGrid': ...
def hide_cells(self, ind: ArrayLike, inplace=False) -> 'StructuredGrid': ...Represents uniform rectilinear grids with regular spacing, commonly used for voxel data and medical imaging.
class ImageData:
"""
Uniform rectilinear grid with regular spacing in all directions.
Attributes:
dimensions: tuple - Grid dimensions (ni, nj, nk)
spacing: tuple - Uniform spacing in each direction
origin: tuple - Origin point coordinates
n_points: int - Number of points
n_cells: int - Number of cells
bounds: tuple - Spatial extent
"""
def __init__(self, dimensions=None, spacing=None, origin=None, **kwargs): ...
# Array access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...
# Image operations
def to_tetrahedra(self) -> UnstructuredGrid: ...
def gaussian_smooth(self, radius_factor=1.5, **kwargs) -> 'ImageData': ...
def median_smooth(self, kernel_size=(3, 3, 3)) -> 'ImageData': ...Represents non-uniform rectilinear grids with variable spacing along coordinate axes.
class RectilinearGrid:
"""
Rectilinear grid with variable spacing along each coordinate axis.
Attributes:
x: np.ndarray - X-coordinate values
y: np.ndarray - Y-coordinate values
z: np.ndarray - Z-coordinate values
dimensions: tuple - Grid dimensions
n_points: int - Number of points
n_cells: int - Number of cells
bounds: tuple - Spatial extent
"""
def __init__(self, x=None, y=None, z=None, **kwargs): ...
# Array access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...Container for multiple datasets of potentially different types.
class MultiBlock:
"""
Composite dataset containing multiple datasets.
Attributes:
n_blocks: int - Number of blocks
bounds: tuple - Combined spatial extent
"""
def __init__(self, *args, **kwargs): ...
# Block access
def __getitem__(self, index: int): ...
def __setitem__(self, index: int, data): ...
def append(self, dataset, name=None): ...
# Operations
def combine(self) -> PolyData: ...
def extract_geometry(self) -> PolyData: ...Represents partitioned datasets for parallel processing.
class PartitionedDataSet:
"""
Partitioned dataset for parallel processing workflows.
Attributes:
n_partitions: int - Number of partitions
bounds: tuple - Combined spatial extent
"""
def __init__(self, *args, **kwargs): ...
# Partition access
def __getitem__(self, index: int): ...
def __setitem__(self, index: int, data): ...Specialized dataset for point cloud data.
class PointGrid:
"""
Point cloud dataset for scattered 3D points.
Attributes:
points: np.ndarray - 3D point coordinates
n_points: int - Number of points
bounds: tuple - Spatial extent
"""
def __init__(self, points=None, **kwargs): ...
# Array access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...Represents tabular data compatible with VTK pipeline.
class Table:
"""
Tabular data structure for storing columnar data.
Attributes:
n_rows: int - Number of rows
n_columns: int - Number of columns
"""
def __init__(self, var_inp=None, **kwargs): ...
# Data access
def __getitem__(self, key: str) -> np.ndarray: ...
def __setitem__(self, key: str, value: ArrayLike): ...Low-level cell representation and connectivity.
class Cell:
"""Individual cell representation with connectivity and type information."""
def __init__(self, cell_type, point_ids): ...
class CellArray:
"""
Array storing cell connectivity information.
Attributes:
n_cells: int - Number of cells
"""
def __init__(self, cells=None, **kwargs): ...
class CellType:
"""Enumeration of VTK cell types."""
# Common cell types
VERTEX: int = 1
LINE: int = 3
TRIANGLE: int = 5
QUAD: int = 9
TETRA: int = 10
HEXAHEDRON: int = 12
WEDGE: int = 13
PYRAMID: int = 14import pyvista as pv
import numpy as np
# Create from points and faces
points = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
faces = np.array([4, 0, 1, 2, 3]) # 4 points in face, then point indices
mesh = pv.PolyData(points, faces)
# Add scalar data
mesh['elevation'] = mesh.points[:, 2]
# Access properties
print(f"Number of points: {mesh.n_points}")
print(f"Number of cells: {mesh.n_cells}")
print(f"Bounds: {mesh.bounds}")import pyvista as pv
import numpy as np
# Create 3D grid
grid = pv.ImageData(dimensions=(50, 50, 50), spacing=(0.1, 0.1, 0.1))
# Add volumetric data
x, y, z = np.meshgrid(np.linspace(-2, 2, 50),
np.linspace(-2, 2, 50),
np.linspace(-2, 2, 50), indexing='ij')
grid['values'] = np.exp(-(x**2 + y**2 + z**2))
# Extract isosurface
contour = grid.contour(isosurfaces=5)Install with Tessl CLI
npx tessl i tessl/pypi-pyvista