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 ofuinput
.
- Parameters:
- uinput
str
,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 avtk.vtkStructuredGrid
, it will be wrapped as a deep copy.If a
numpy.ndarray
is provided andy
andz
are empty, this array will define the points of thisStructuredGrid
. Set the dimensions withStructuredGrid.dimensions
.Otherwise, this parameter will be loaded as the
x
points, andy
andz
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 be1
.- y
numpy.ndarray
,optional
Coordinates of the points in y direction. If this is passed,
uinput
must be anumpy.ndarray
and match the shape ofy
.- z
numpy.ndarray
,optional
Coordinates of the points in z direction. If this is passed,
uinput
andy
must be anumpy.ndarray
and match the shape ofz
.- deep
optional
Whether to deep copy a StructuredGrid object. Default is
False
. Keyword only.- **kwargs
dict
,optional
Additional keyword arguments passed when reading from a file or loading from arrays.
- uinput
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.
Hide points without deleting them.
Attributes
Return a length 3 tuple of the grid's dimensions.
Points as a 4-D matrix, with x/y/z along the last dimension.
Return the X coordinates of all points.
Return the Y coordinates of all points.
Return the Z coordinates of all points.