PyVista is a high-level Pythonic interface to the Visualization Toolkit (VTK), simplifying 3D plotting, mesh data structures, and filtering methods for spatial datasets. It is an active project, currently at version 0.47.3, with frequent patch releases and minor versions addressing bugs and introducing new features.
pip install pyvistaVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to download a sample 3D mesh, assign scalar data to its points for coloring, and then visualize it using PyVista's `Plotter` with a specified colormap and camera position.
To obtain image depth after the plotter closes, you must explicitly enable `store_image_depth=True` in the `show()` method (e.g., `plotter.show(store_image_depth=True)`).
In v0.46.0 and v0.46.1, you had to use `pyvista.set_new_attribute(obj, name, value)`. In v0.46.3+, this was relaxed: new *public* attributes still require `set_new_attribute()`, but *private* attributes (prefixed with `_`) can be set directly.
Upgrade to PyVista v0.46.4 or later, which re-enabled the caching mechanism and resolved the performance degradation.
Use the `DataSetAttributes.get_array(index)` method instead of the `[]` operator for integer indexing. String-based access (`obj['array_name']`) remains valid.
Install PyVista using pip: `pip install pyvista`
Enable off-screen rendering by setting `pyvista.OFF_SCREEN = True` before any plotting, and ensure an appropriate off-screen VTK backend (like `osmesa` or `egl`) is available, or use `xvfb`. Example: `import pyvista; pyvista.OFF_SCREEN = True; # your plotting code`
Replace `mesh.scalars` with `mesh.active_scalars` to access the active scalar array. Example: `mesh.active_scalars`
Choose one of the valid backend names from the error message. Example: `pyvista.set_jupyter_backend('ipyvtk_simple')`Use the PyVista-style method: `plotter.add_actor(...)`