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.- deepbool, default:
False Whether to deep copy a StructuredGrid object. Default is
False. Keyword only.- validatebool |
MeshValidationFields| sequence[MeshValidationFields], default:False Validate the mesh using
validate_mesh()after initialization. Set this toTrueto validate all fields, or specify any combination of fields allowed byvalidate_mesh.Added in version 0.47.
- **kwargs
dict,optional Additional keyword arguments passed when reading from a file or loading from arrays.
- uinput
Examples#
Download Python source code | Download Jupyter notebook
>>> 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.
Used In#
Docstring Examples
Gallery Examples
- Applying Textures
- Colormap Choices
- Control Global and Local Plotting Themes
- Create Sphere Mesh Multiple Ways
- Create a GIF Movie
20 more
- Create a GIF Movie of a Static Object with a Moving Colormap
- Creating a Structured Surface
- Customize Scalar Bars
- Display Eigenmodes of Vibration
- Drape 2D Surface From Line
- Fast Fourier Transform with Perlin Noise
- Lighting Properties
- Line Widget
- Load data using a Reader
- Orbiting
- Plot Over Line
- Plot data in spherical coordinates
- Plot with Opacity
- Plotter Lighting Systems
- Save a Movie Using Glyphs
- Sphere Widget
- Table of Glyphs
- Terrain Following Mesh
- Topographic Map
- Turning the sphere inside out
Guides
Methods#
Cast to an explicit structured grid. |
|
|
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. |