pyvista.StructuredGrid#

class StructuredGrid(*args, **kwargs)[source]#

Dataset used for topologically regular arrays of data.

Can be initialized in one of the following several ways:

  • Create empty grid.

  • Initialize from a filename.

  • Initialize from a vtk.vtkStructuredGrid object.

  • Initialize directly from one or more numpy.ndarray. See the example or the documentation of uinput.

Parameters:
uinputstr, Path, vtk.vtkStructuredGrid, numpy.ndarray, optional

Filename, dataset, or array to initialize the structured grid from. If a filename is passed, pyvista will attempt to load it as a StructuredGrid. If passed a vtk.vtkStructuredGrid, it will be wrapped as a deep copy.

If a numpy.ndarray is provided and y and z are empty, this array will define the points of this StructuredGrid. Set the dimensions with StructuredGrid.dimensions.

Otherwise, this parameter will be loaded as the x points, and y and z points must be set. The shape of this array defines the shape of the structured data and the shape should be (dimx, dimy, dimz). Missing trailing dimensions are assumed to be 1.

ynumpy.ndarray, optional

Coordinates of the points in y direction. If this is passed, uinput must be a numpy.ndarray and match the shape of y.

znumpy.ndarray, optional

Coordinates of the points in z direction. If this is passed, uinput and y must be a numpy.ndarray and match the shape of z.

deepoptional

Whether to deep copy a StructuredGrid object. Default is False. Keyword only.

**kwargsdict, optional

Additional keyword arguments passed when reading from a file or loading from arrays.

Examples

>>> import pyvista as pv
>>> import vtk
>>> import numpy as np

Create an empty structured grid.

>>> grid = pv.StructuredGrid()

Initialize from a vtk.vtkStructuredGrid object

>>> vtkgrid = vtk.vtkStructuredGrid()
>>> grid = pv.StructuredGrid(vtkgrid)

Create from NumPy arrays.

>>> xrng = np.arange(-10, 10, 2, dtype=np.float32)
>>> yrng = np.arange(-10, 10, 5, dtype=np.float32)
>>> zrng = np.arange(-10, 10, 1, dtype=np.float32)
>>> x, y, z = np.meshgrid(xrng, yrng, zrng, indexing='ij')
>>> grid = pv.StructuredGrid(x, y, z)
>>> grid
StructuredGrid (...)
  N Cells:      513
  N Points:     800
  X Bounds:     -1.000e+01, 8.000e+00
  Y Bounds:     -1.000e+01, 5.000e+00
  Z Bounds:     -1.000e+01, 9.000e+00
  Dimensions:   10, 4, 20
  N Arrays:     0

Methods

StructuredGrid.hide_cells(ind[, inplace])

Hide cells without deleting them.

StructuredGrid.hide_points(ind)

Hide points without deleting them.

Attributes

StructuredGrid.dimensions

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

StructuredGrid.points_matrix

Points as a 4-D matrix, with x/y/z along the last dimension.

StructuredGrid.x

Return the X coordinates of all points.

StructuredGrid.y

Return the Y coordinates of all points.

StructuredGrid.z

Return the Z coordinates of all points.