Gridded Data

Gridded datasets in pyvista capture vtkRectilinearGrid and vtkImageData data objects on the VTK backend. These data types have common features which are encompassed int their shared inheritance of pyvista.Grid

Attributes

dimensions

Return a length 3 tuple of the grid’s dimensions.

Methods

class pyvista.Grid(*args, **kwargs)

Bases: pyvista.core.common.Common

A class full of common methods for non-pointset grids.

property dimensions

Return a length 3 tuple of the grid’s dimensions.

These are effectively the number of nodes along each of the three dataset axes.

Rectilinear Grid

Attributes

dimensions

Return a length 3 tuple of the grid’s dimensions.

meshgrid

Return a meshgrid of numpy arrays for this mesh.

points

Return a copy of the points as an n by 3 numpy array.

x

Get the coordinates along the X-direction.

y

Get the coordinates along the Y-direction.

z

Get the coordinates along the Z-direction.

Methods

cast_to_structured_grid()

Cast this rectilinear grid to a pyvista.StructuredGrid.

class pyvista.RectilinearGrid(*args, **kwargs)

Bases: vtkmodules.vtkCommonDataModel.vtkRectilinearGrid, pyvista.core.grid.Grid

Extend the functionality of a vtk.vtkRectilinearGrid object.

Can be initialized in several ways:

  • Create empty grid

  • Initialize from a vtk.vtkRectilinearGrid object

  • Initialize directly from the point arrays

See _from_arrays in the documentation for more details on initializing from point arrays

Examples

>>> import pyvista
>>> import vtk
>>> import numpy as np
>>> # Create empty grid
>>> grid = pyvista.RectilinearGrid()
>>> # Initialize from a vtk.vtkRectilinearGrid object
>>> vtkgrid = vtk.vtkRectilinearGrid()
>>> grid = pyvista.RectilinearGrid(vtkgrid)
>>> # Create from NumPy arrays
>>> xrng = np.arange(-10, 10, 2)
>>> yrng = np.arange(-10, 10, 5)
>>> zrng = np.arange(-10, 10, 1)
>>> grid = pyvista.RectilinearGrid(xrng, yrng, zrng)
cast_to_structured_grid()

Cast this rectilinear grid to a pyvista.StructuredGrid.

property dimensions

Return a length 3 tuple of the grid’s dimensions.

These are effectively the number of nodes along each of the three dataset axes.

property meshgrid

Return a meshgrid of numpy arrays for this mesh.

This simply returns a numpy.meshgrid of the coordinates for this mesh in ij indexing. These are a copy of the points of this mesh.

property points

Return a copy of the points as an n by 3 numpy array.

property x

Get the coordinates along the X-direction.

property y

Get the coordinates along the Y-direction.

property z

Get the coordinates along the Z-direction.

Uniform Grid

PyVista’s definition of a uniform grid is an extension of VTK’s vtkImageData

Attributes

origin

Return the origin of the grid (bottom southwest corner).

points

Build a copy of the implicitly defined points as a numpy array.

spacing

Get the spacing for each axial direction.

x

Return all the X points.

y

Return all the Y points.

z

Return all the Z points.

Methods

cast_to_rectilinear_grid()

Cast this uniform grid to a pyvista.RectilinearGrid.

cast_to_structured_grid()

Cast this uniform grid to a pyvista.StructuredGrid.

class pyvista.UniformGrid(*args, **kwargs)

Bases: vtkmodules.vtkCommonDataModel.vtkImageData, pyvista.core.grid.Grid, pyvista.core.filters.UniformGridFilters

Extend the functionality of a vtk.vtkImageData object.

Can be initialized in several ways:

  • Create empty grid

  • Initialize from a vtk.vtkImageData object

  • Initialize directly from the point arrays

See _from_specs in the documentation for more details on initializing from point arrays

Examples

>>> import pyvista
>>> import vtk
>>> import numpy as np
>>> # Create empty grid
>>> grid = pyvista.UniformGrid()
>>> # Initialize from a vtk.vtkImageData object
>>> vtkgrid = vtk.vtkImageData()
>>> grid = pyvista.UniformGrid(vtkgrid)
>>> # Using just the grid dimensions
>>> dims = (10, 10, 10)
>>> grid = pyvista.UniformGrid(dims)
>>> # Using dimensions and spacing
>>> spacing = (2, 1, 5)
>>> grid = pyvista.UniformGrid(dims, spacing)
>>> # Using dimensions, spacing, and an origin
>>> origin = (10, 35, 50)
>>> grid = pyvista.UniformGrid(dims, spacing, origin)
cast_to_rectilinear_grid()

Cast this uniform grid to a pyvista.RectilinearGrid.

cast_to_structured_grid()

Cast this uniform grid to a pyvista.StructuredGrid.

property origin

Return the origin of the grid (bottom southwest corner).

property points

Build a copy of the implicitly defined points as a numpy array.

property spacing

Get the spacing for each axial direction.

property x

Return all the X points.

property y

Return all the Y points.

property z

Return all the Z points.