General Utilities

pyvista.set_error_output_file(filename)

Sets a file to write out the VTK errors

pyvista.trans_from_matrix(matrix)

Convert a vtk matrix to a numpy.ndarray

pyvista.is_inside_bounds(point, bounds)

Checks if a point is inside a set of bounds. This is implemented through recursion so that this is N-dimensional.

Object Conversions

pyvista.wrap(vtkdataset)

This is a convenience method to safely 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.

pyvista.is_pyvista_dataset(obj)

Return True if the Object is a PyVista wrapped dataset

pyvista.image_to_texture(image)

Converts vtkImageData (pyvista.UniformGrid) to a vtkTexture

pyvista.numpy_to_texture(image)

Convert a NumPy image array to a vtk.vtkTexture

File IO

pyvista.read(filename, attrs=None)

This will read any VTK file! It will figure out what reader to use then wrap the VTK object for use in PyVista.

Parameters

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.

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)

Loads a vtkTexture from an image file.

pyvista.read_legacy(filename)

Use VTK’s legacy reader to read a file

Mesh Creation

pyvista.lines_from_points(points)

Generates line from points. Assumes points are ordered as line segments.

Parameters

points (np.ndarray) –

Points representing line segments. For example, two line segments would be represented as:

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

Returns

lines – PolyData with lines and cells.

Return type

pyvista.PolyData

Examples

This example plots two line segments at right angles to each other line.

>>> import pyvista
>>> import numpy as np
>>> points = np.array([[0, 0, 0], [1, 0, 0], [1, 0, 0], [1, 1, 0]])
>>> lines = pyvista.lines_from_points(points)
>>> lines.plot() 
pyvista.vtk_points(points, deep=True)

Convert numpy points to a vtkPoints object

pyvista.vector_poly_data(orig, vec)

Creates a vtkPolyData object composed of vectors

pyvista.fit_plane_to_points(points, return_meta=False)

Fits a plane to a set of points

Parameters
  • 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)

Searches point, cell and field data for an array

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

  • preference (str, optional) – When scalars is specified, this is the perfered scalar type to search for in the dataset. Must be either 'point', 'cell', or 'field'

  • info (bool) – Return info about the scalar 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)

A helper to convert a NumPy array to a vtkDataArray or vice versa

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

Returns

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_scalar(mesh, name)

Returns point scalars of a vtk object

pyvista.cell_scalar(mesh, name)

Returns cell scalars of a vtk object

pyvista.get_vtk_type(typ)

This looks up the VTK type for a give python data type. Corrects for string type mapping issues.

Returns

int

Return type

the integer type id specified in vtkType.h

pyvista.vtk_bit_array_to_char(vtkarr_bint)

Cast vtk bit array to a char array

pyvista.convert_string_array(arr, name=None)

A helper to 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.