DatasetsÂ¶
Datasets are any spatially reference information and usually consist of
geometrical representations of a surface or volume in 3D space.
In VTK, this superclass is represented by the vtk.vtkDataSet
abstract class.
In VTK, datasets consist of geometry, topology, and attributes to which PyVista provides direct access:
Geometry is the collection of points and cells in 2D or 3D space.
Topology defines the structure of the dataset, or how the points are connected to each other to form a cells making a surface or volume.
Attributes are any data values that are associated to either the points or cells of the dataset
All of the following data types are listed subclasses of a dataset and share a
set of common functionality which we wrap into the base class
pyvista.DataSet
.
The DataSet ModelÂ¶
The pyvista.DataSet
class holds attributes that are common to all
spatially referenced datasets in PyVista.
This base class is analogous to VTKâ€™s vtk.vtkDataSet
class.
Attributes
Return the active scalars as an array. 

[field, name]. 

Return the active scalarâ€™s name. 

Return the active tensors array. 

[field, name]. 

Return the name of the active tensor array. 

Return the active vectors array. 

[field, name]. 

Return the name of the active vectors array. 

Return a list of array names for the dataset. 

Return a glyph representation of the active vector data as arrows. 

Return the bounding box of this dataset. 

Return vtkCellData as DataSetAttributes. 

Return the center of the bounding box. 

Return the range of the bounding box. 

Return the length of the diagonal of the bounding box. 

Return the number of arrays present in the dataset. 

Return the number of cells in the entire dataset. 

Return the number of points in the entire dataset. 

Return the number of cells. 

Return the number of points. 

Return vtkPointData as DataSetAttributes. 

Return a pointer to the points as a numpy object. 

Return the active texture coordinates on the points. 

Return a dictionary to hold compatible 

Return active vectors. 

Return the mesh volume. 
Methods
Get a new representation of this object as an 


Return the bounding box of a cell. 

Return the number of points in a cell. 

Return the points in a cell. 

Return the type of a cell. 
Remove all arrays from point/cell/field data. 

Remove all cell arrays. 

Remove all point arrays. 

Clear the textures from this mesh. 


Copy pyvista meta data onto this object from another object. 

Find index of closest cell in this mesh to the given point. 

Find index of closest point in this mesh to the given point. 

Search both point, cell and field data for an array. 

Get the nonNaN min and max of a named array. 

Overwrite this mesh inplace with the new meshâ€™s geometries and data. 

Plot a vtk or numpy object. 
Make points double precision. 


Change array name by searching for the array then renaming it. 

Rotate mesh about the xaxis. 

Rotate mesh about the yaxis. 

Rotate mesh about the zaxis. 

Find the scalars by name and appropriately sets it as active. 

Find the tensors by name and appropriately sets it as active. 

Find the vectors by name and appropriately sets it as active. 

Translate the mesh. 

class
pyvista.
DataSet
(*args, **kwargs)Â¶ Bases:
pyvista.core.filters.DataSetFilters
,pyvista.core.dataobject.DataObject
Methods in common to spatially referenced objects.

property
active_scalars
Â¶ Return the active scalars as an array.

property
active_scalars_info
Â¶ [field, name].
 Type
Return the active scalarâ€™s field and name

property
active_scalars_name
Â¶ Return the active scalarâ€™s name.

property
active_tensors
Â¶ Return the active tensors array.

property
active_tensors_info
Â¶ [field, name].
 Type
Return the active tensorâ€™s field and name

property
active_tensors_name
Â¶ Return the name of the active tensor array.

property
active_vectors
Â¶ Return the active vectors array.

property
active_vectors_info
Â¶ [field, name].
 Type
Return the active scalarâ€™s field and name

property
active_vectors_name
Â¶ Return the name of the active vectors array.

property
array_names
Â¶ Return a list of array names for the dataset.
This makes sure to put the active scalarsâ€™ name first in the list.

property
arrows
Â¶ Return a glyph representation of the active vector data as arrows.
Arrows will be located at the points of the mesh and their size will be dependent on the length of the vector. Their direction will be the â€śdirectionâ€ť of the vector
 Returns
arrows â€“ Active scalars represented as arrows.
 Return type

property
bounds
Â¶ Return the bounding box of this dataset.
The form is: (xmin,xmax, ymin,ymax, zmin,zmax).

cast_to_unstructured_grid
() → pyvista.core.pointset.UnstructuredGridÂ¶ Get a new representation of this object as an
pyvista.UnstructuredGrid
.

property
cell_arrays
Â¶ Return vtkCellData as DataSetAttributes.

cell_bounds
(ind: int) → List[float]Â¶ Return the bounding box of a cell.
 Parameters
ind (int) â€“ Cell ID.
 Returns
The limits of the cell in the X, Y and Z directions respectivelly.
 Return type
list(float)
Examples
>>> from pyvista import examples >>> mesh = examples.load_airplane() >>> mesh.cell_bounds(0) [896.9940185546875, 907.5390014648438, 48.760101318359375, 55.49020004272461, 80.74520111083984, 83.65809631347656]

cell_n_points
(ind: int) → intÂ¶ Return the number of points in a cell.
 Parameters
ind (int) â€“ Cell ID.
 Returns
Number of points in the cell.
 Return type
int
Examples
>>> from pyvista import examples >>> mesh = examples.load_airplane() >>> mesh.cell_n_points(0) 3

cell_points
(ind: int) → numpy.ndarrayÂ¶ Return the points in a cell.
 Parameters
ind (int) â€“ Cell ID.
 Returns
An array of floats with shape (number of points, 3) containing the coordinates of the cell corners.
 Return type
numpy.ndarray
Examples
>>> from pyvista import examples >>> mesh = examples.load_airplane() >>> mesh.cell_points(0) [[896.99401855 48.76010132 82.26560211] [906.59301758 48.76010132 80.74520111] [907.53900146 55.49020004 83.65809631]]

cell_type
(ind: int) → intÂ¶ Return the type of a cell.
 Parameters
ind (int) â€“ Cell ID.
 Returns
VTK cell type. See <https://vtk.org/doc/nightly/html/vtkCellType_8h_source.html>.
 Return type
int
Examples
>>> from pyvista import examples >>> mesh = examples.load_airplane() >>> mesh.cell_type(0) 5

property
center
Â¶ Return the center of the bounding box.

clear_arrays
()Â¶ Remove all arrays from point/cell/field data.

clear_cell_arrays
()Â¶ Remove all cell arrays.

clear_point_arrays
()Â¶ Remove all point arrays.

clear_textures
()Â¶ Clear the textures from this mesh.

copy_meta_from
(ido: pyvista.core.dataset.DataSet)Â¶ Copy pyvista meta data onto this object from another object.

property
extent
Â¶ Return the range of the bounding box.

find_closest_cell
(point: Union[int, numpy.ndarray]) → Union[int, numpy.ndarray]Â¶ Find index of closest cell in this mesh to the given point.
 Parameters
point (iterable(float) or np.ndarray) â€“ Length 3 coordinate of the point to query or a
numpy
array of coordinates. Returns
index â€“ Index or indices of the cell in this mesh that is closest to the given point.
 Return type
int or np.ndarray
Examples
Find nearest cell to a point on a sphere
>>> import pyvista >>> mesh = pyvista.Sphere() >>> index = mesh.find_closest_cell([0, 0, 0.5]) >>> index 59
Find the nearest cells to several random points. Note that
1
indicates that the locator was not able to find a reasonably close cell.>>> import numpy as np >>> points = np.random.random((1000, 3)) >>> indices = mesh.find_closest_cell(points) >>> print(indices.shape) (1000,)

find_closest_point
(point: Iterable[float], n=1) → intÂ¶ Find index of closest point in this mesh to the given point.
If wanting to query many points, use a KDTree with scipy or another library as those implementations will be easier to work with.
See: https://github.com/pyvista/pyvistasupport/issues/107
 Parameters
point (iterable(float)) â€“ Length 3 coordinate of the point to query.
n (int, optional) â€“ If greater than
1
, returns the indices of then
closest points.
 Returns
int
 Return type
the index of the point in this mesh that is closes to the given point.

get_array
(name: str, preference='cell', info=False) → Union[Tuple, numpy.ndarray]Â¶ Search both point, cell and field data for an array.

get_data_range
(arr_var: Optional[Union[str, numpy.ndarray]] = None, preference='cell') → Tuple[Union[float, numpy.ndarray], Union[float, numpy.ndarray]]Â¶ Get the nonNaN min and max of a named array.
 Parameters
arr_var (str, np.ndarray, optional) â€“ The name of the array to get the range. If
None
, the active scalars is used.preference (str, optional) â€“ When scalars is specified, this is the preferred array type to search for in the dataset. Must be either
'point'
,'cell'
, or'field'
.

property
length
Â¶ Return the length of the diagonal of the bounding box.

property
n_arrays
Â¶ Return the number of arrays present in the dataset.

property
n_cells
Â¶ Return the number of cells in the entire dataset.

property
n_points
Â¶ Return the number of points in the entire dataset.

property
number_of_cells
Â¶ Return the number of cells.

property
number_of_points
Â¶ Return the number of points.

overwrite
(mesh: vtkmodules.vtkCommonDataModel.vtkDataSet)Â¶ Overwrite this mesh inplace with the new meshâ€™s geometries and data.
 Parameters
mesh (vtk.vtkDataSet) â€“ The overwriting mesh.

plot
(off_screen=None, full_screen=False, screenshot=None, interactive=True, cpos=None, window_size=None, show_bounds=False, show_axes=True, notebook=None, background=None, text='', return_img=False, eye_dome_lighting=False, volume=False, parallel_projection=False, use_ipyvtk=None, jupyter_backend=None, return_viewer=False, jupyter_kwargs={}, **kwargs)Â¶ Plot a vtk or numpy object.
 Parameters
item (vtk or numpy object) â€“ VTK object or
numpy
array to be plotted.off_screen (bool) â€“ Plots off screen when
True
. Helpful for saving screenshots without a window popping up.full_screen (bool, optional) â€“ Opens window in full screen. When enabled, ignores
window_size
. DefaultFalse
.screenshot (str or bool, optional) â€“
Saves screenshot to file when enabled. See:
help(pyvista.Plotter.screenshot)
. DefaultFalse
.When
True
, takes screenshot and returnsnumpy
array of image.window_size (list, optional) â€“ Window size in pixels. Defaults to
[1024, 768]
show_bounds (bool, optional) â€“ Shows mesh bounds when
True
. DefaultFalse
. Aliasshow_grid
also accepted.notebook (bool, optional) â€“ When
True
, the resulting plot is placed inline a jupyter notebook. Assumes a jupyter console is active.show_axes (bool, optional) â€“ Shows a vtk axes widget. Enabled by default.
text (str, optional) â€“ Adds text at the bottom of the plot.
volume (bool, optional) â€“ Use the
add_volume
method for volume rendering.use_ipyvtk (bool, optional) â€“ Deprecated. Instead, set the backend either globally with
pyvista.set_jupyter_backend('ipyvtklink')
or withbackend='ipyvtklink'
.jupyter_backend (str, optional) â€“
Jupyter notebook plotting backend to use. One of the following:
'none'
: Do not display in the notebook.'static'
: Display a static figure.'ipygany'
: Show aipygany
widget'panel'
: Show apanel
widget.
This can also be set globally with
pyvista.set_jupyter_backend
jupyter_kwargs (dict, optional) â€“ Keyword arguments for the Jupyter notebook plotting backend.
**kwargs (optional keyword arguments) â€“ See help(Plotter.add_mesh) for additional options.
 Returns
cpos (list) â€“ List of camera position, focal point, and view up.
img (numpy.ndarray) â€“ Array containing pixel RGB and alpha. Sized: [Window height x Window width x 3] for transparent_background=False [Window height x Window width x 4] for transparent_background=True Returned only when screenshot enabled

property
point_arrays
Â¶ Return vtkPointData as DataSetAttributes.

property
points
Â¶ Return a pointer to the points as a numpy object.

points_to_double
()Â¶ Make points double precision.

rename_array
(old_name: str, new_name: str, preference='cell')Â¶ Change array name by searching for the array then renaming it.

rotate_x
(angle: float, transform_all_input_vectors=False)Â¶ Rotate mesh about the xaxis.
 Parameters
angle (float) â€“ Angle in degrees to rotate about the xaxis.

rotate_y
(angle: float, transform_all_input_vectors=False)Â¶ Rotate mesh about the yaxis.
 Parameters
angle (float) â€“ Angle in degrees to rotate about the yaxis.

rotate_z
(angle: float, transform_all_input_vectors=False)Â¶ Rotate mesh about the zaxis.
 Parameters
angle (float) â€“ Angle in degrees to rotate about the zaxis.

set_active_scalars
(name: str, preference='cell')Â¶ Find the scalars by name and appropriately sets it as active.
To deactivate any active scalars, pass
None
as thename
.

set_active_tensors
(name: str, preference='point')Â¶ Find the tensors by name and appropriately sets it as active.
To deactivate any active tensors, pass
None
as thename
.

set_active_vectors
(name: str, preference='point')Â¶ Find the vectors by name and appropriately sets it as active.
To deactivate any active vectors, pass
None
as thename
.

property
t_coords
Â¶ Return the active texture coordinates on the points.

property
textures
Â¶ Return a dictionary to hold compatible
vtk.vtkTexture
objects.When casting back to a VTK dataset or filtering this dataset, these textures will not be passed.

translate
(xyz: Union[list, tuple, numpy.ndarray])Â¶ Translate the mesh.
 Parameters
xyz (list or tuple or np.ndarray) â€“ Length 3 list, tuple or array.

property
vectors
Â¶ Return active vectors.

property
volume
Â¶ Return the mesh volume.
 Returns
volume â€“ Total volume of the mesh.
 Return type
float

property