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 vtkStructuredGrid object.
Initialize directly from one or more
numpy.ndarray. See the example or the documentation ofuinput.
- Parameters:
- uinput
str,Path, 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 vtkStructuredGrid, it will be wrapped as a deep copy.If a
numpy.ndarrayis provided andyandzare empty, this array will define the points of thisStructuredGrid. Set the dimensions withStructuredGrid.dimensions.Otherwise, this parameter will be loaded as the
xpoints, andyandzpoints 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,
uinputmust be anumpy.ndarrayand match the shape ofy.- z
numpy.ndarray,optional Coordinates of the points in z direction. If this is passed,
uinputandymust be anumpy.ndarrayand 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
See also
Examples
>>> import pyvista as pv >>> import vtk >>> import numpy as np
Create an empty structured grid.
>>> grid = pv.StructuredGrid()
Initialize from a vtkStructuredGrid object
>>> vtkgrid = vtk.vtkStructuredGrid() >>> grid = pv.StructuredGrid(vtkgrid)
Create from NumPy arrays using
numpy.meshgrid().>>> xrng = np.linspace(-5, 5, 10) >>> yrng = np.linspace(-8, 8, 4) >>> zrng = np.linspace(-7, 4, 20) >>> 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: -5.000e+00, 5.000e+00 Y Bounds: -8.000e+00, 8.000e+00 Z Bounds: -7.000e+00, 4.000e+00 Dimensions: 10, 4, 20 N Arrays: 0
Note how the grid dimensions match the shape of the input arrays.
>>> (xrng.size, yrng.size, zrng.size) (10, 4, 20)
Methods
Cast to an explicit structured grid.
StructuredGrid.hide_cells(ind[, inplace])Hide cells without deleting them.
Hide points without deleting them.
Attributes
Return the dimensionality of the grid.
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.