General Utilities

Utilities routines.


Set a file to write out the VTK errors.


Convert a vtk matrix to a numpy.ndarray.

pyvista.is_inside_bounds(point, bounds)

Check if a point is inside a set of bounds.

This is implemented through recursion so that this is N-dimensional.

Object Conversions


Wrap any given VTK data object to its appropriate PyVista data object.

Other formats that are supported include: * 2D numpy.ndarray of XYZ vertices * 3D numpy.ndarray representing a volume. Values will be scalars.


Return True if the Object is a PyVista wrapped dataset.


Convert vtkImageData (pyvista.UniformGrid) to a vtkTexture.


Convert a NumPy image array to a vtk.vtkTexture.

File IO, attrs=None, file_format=None)

Read any VTK file.

It will figure out what reader to use then wrap the VTK object for use in PyVista.

  • filename (str) – The string path to the file to read. If a list of files is given, a pyvista.MultiBlock dataset is returned with each file being a separate block in the dataset.

  • attrs (dict, optional) – A dictionary of attributes to call on the reader. Keys of dictionary are the attribute/method names and values are the arguments passed to those calls. If you do not have any attributes to call, pass None as the value.

  • file_format (str, optional) – Format of file to read with meshio.


Load an example mesh

>>> import pyvista
>>> from pyvista import examples
>>> mesh =

Load a vtk file

>>> mesh ='my_mesh.vtk')  

Load a meshio file

>>> mesh ="mesh.obj")  
pyvista.read_exodus(filename, animate_mode_shapes=True, apply_displacements=True, displacement_magnitude=1.0, enabled_sidesets=None)

Read an ExodusII file ('.e' or '.exo').

pyvista.read_texture(filename, attrs=None)

Load a vtkTexture from an image file.


Use VTK’s legacy reader to read a file.

pyvista.save_meshio(filename, mesh, file_format=None, **kwargs)

Save mesh to file using meshio.

  • mesh (pyvista.Common) – Any PyVista mesh/spatial data type.

  • file_format (str) – File type for meshio to save.

Mesh Creation

pyvista.lines_from_points(points, close=False)

Make a connected line set given an array of points.

  • points (np.ndarray) –

    Points representing the vertices of the connected segments. For example, two line segments would be represented as:

    np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0]])

  • close (bool, optional) – If True, close the line segments into a loop


lines – PolyData with lines and cells.

Return type


pyvista.vtk_points(points, deep=True)

Convert numpy points to a vtkPoints object.

pyvista.vector_poly_data(orig, vec)

Create a vtkPolyData object composed of vectors.

pyvista.fit_plane_to_points(points, return_meta=False)

Fit a plane to a set of points.

  • points (np.ndarray) – Size n by 3 array of points to fit a plane through

  • return_meta (bool) – If true, also returns the center and normal used to generate the plane

Array Access

pyvista.get_array(mesh, name, preference='cell', info=False, err=False)

Search point, cell and field data for an array.

  • name (str) – The name of the array to get the range.

  • 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'

  • info (bool) – Return info about the array rather than the array itself.

  • err (bool) – Boolean to control whether to throw an error if array is not present.

pyvista.convert_array(arr, name=None, deep=0, array_type=None)

Convert a NumPy array to a vtkDataArray or vice versa.

  • arr (ndarray or vtkDataArry) – A numpy array or vtkDataArry to convert

  • name (str) – The name of the data array for VTK

  • deep (bool) – if input is numpy array then deep copy values


the converted array (if input is a NumPy ndaray then returns vtkDataArray or is input is vtkDataArray then returns NumPy ndarray). If pdf==True and the input is vtkDataArry, return a pandas DataFrame.

Return type

vtkDataArray, ndarray, or DataFrame

pyvista.point_array(mesh, name)

Return point array of a vtk object.

pyvista.cell_array(mesh, name)

Return cell array of a vtk object.

pyvista.field_array(mesh, name)

Return field array of a vtk object.


Look up the VTK type for a give python data type.

Corrects for string type mapping issues.



Return type

the integer type id specified in vtkType.h


Cast vtk bit array to a char array.

pyvista.convert_string_array(arr, name=None)

Convert a numpy array of strings to a vtkStringArray or vice versa.

Note that this is terribly inefficient - inefficient support is better than no support :). If you have ideas on how to make this faster, please consider opening a pull request.