PyVista 3D Visualization
Overview
PyVista (MIT, 3.6k stars) is a Pythonic wrapper around VTK for 3D spatial data visualization. It provides a streamlined API for rendering meshes, point clouds, STL/OBJ geometry, and scalar fields without low-level VTK boilerplate.
Key Capabilities
| Feature |
Details |
| Mesh rendering |
Surface, wireframe, point cloud, volume rendering |
| Scalar coloring |
Map data arrays to colormaps (coolwarm, viridis, plasma, etc.) |
| File I/O |
STL, OBJ, PLY, VTK, VTP --- plus all meshio-supported formats |
| Offscreen rendering |
off_screen=True for headless/CI environments |
| GPU acceleration |
Uses OpenGL via VTK; works with NVIDIA GPUs |
| Jupyter integration |
Interactive 3D in notebooks via trame |
| Mesh quality |
Built-in quality metrics (scaled Jacobian, aspect ratio, etc.) |
| Engineering use |
Pipe geometry, FEA results, terrain, bathymetry, point clouds |
Quick Start
import pyvista as pv
# Load and render a mesh
mesh = pv.read("geometry.stl")
mesh.plot(scalars="pressure", cmap="coolwarm")
# Offscreen rendering
plotter = pv.Plotter(off_screen=True, window_size=(1280, 720))
plotter.add_mesh(mesh, scalars="depth", cmap="viridis")
plotter.screenshot("output.png")
plotter.close()
# Pipe geometry from spline
import numpy as np
t = np.linspace(0, 10, 50)
points = np.column_stack((t, np.zeros_like(t), np.cosh((t-5)/5)))
spline = pv.Spline(points, n_points=200)
pipe = spline.tube(radius=0.15, n_sides=20)
pipe.plot()
Environment
- Python: >= 3.10
- Tested: PyVista 0.47.1, VTK 9.6.0, NVIDIA GTX 750 Ti
- Headless: Set
PYVISTA_OFF_SCREEN=true or use off_screen=True in Plotter
Headless Fallback Pattern
When the deliverable is an engineering animation/video and the full VTK/PyVista/ParaView rendering path is temporarily unavailable, unstable in the current runtime, or overkill for a first-pass approximation, use a deterministic raw RGB frame pipeline into ffmpeg. Keep the artifact clearly labeled as a visualization fallback, not a validated solver output, and verify it with ffprobe plus a preview frame before delivery.
Reference: references/rawvideo-ffmpeg-headless-fallback.md
Known Issues
cell_quality() segfaults on tube meshes with VTK 9.6; use deprecated compute_cell_quality() until PyVista 0.48+
- First render in a session takes 500-700ms (OpenGL context init); subsequent renders are 35ms
Related Skills
References
1---2name: pyvista-3d-23description: AI interface skill for PyVista 3D visualization --- VTK wrapper for mesh rendering, STL/OBJ/VTK I/O, scalar coloring, offscreen rendering, and engineering analysis post-processing.4---56# PyVista 3D Visualization78## Overview910PyVista (MIT, 3.6k stars) is a Pythonic wrapper around VTK for 3D spatial data visualization. It provides a streamlined API for rendering meshes, point clouds, STL/OBJ geometry, and scalar fields without low-level VTK boilerplate.1112## Key Capabilities1314| Feature | Details |15|---------|---------|16| Mesh rendering | Surface, wireframe, point cloud, volume rendering |17| Scalar coloring | Map data arrays to colormaps (coolwarm, viridis, plasma, etc.) |18| File I/O | STL, OBJ, PLY, VTK, VTP --- plus all meshio-supported formats |19| Offscreen rendering | `off_screen=True` for headless/CI environments |20| GPU acceleration | Uses OpenGL via VTK; works with NVIDIA GPUs |21| Jupyter integration | Interactive 3D in notebooks via trame |22| Mesh quality | Built-in quality metrics (scaled Jacobian, aspect ratio, etc.) |23| Engineering use | Pipe geometry, FEA results, terrain, bathymetry, point clouds |2425## Quick Start2627```python28import pyvista as pv2930# Load and render a mesh31mesh = pv.read("geometry.stl")32mesh.plot(scalars="pressure", cmap="coolwarm")3334# Offscreen rendering35plotter = pv.Plotter(off_screen=True, window_size=(1280, 720))36plotter.add_mesh(mesh, scalars="depth", cmap="viridis")37plotter.screenshot("output.png")38plotter.close()3940# Pipe geometry from spline41import numpy as np42t = np.linspace(0, 10, 50)43points = np.column_stack((t, np.zeros_like(t), np.cosh((t-5)/5)))44spline = pv.Spline(points, n_points=200)45pipe = spline.tube(radius=0.15, n_sides=20)46pipe.plot()47```4849## Environment5051- **Python**: >= 3.1052- **Tested**: PyVista 0.47.1, VTK 9.6.0, NVIDIA GTX 750 Ti53- **Headless**: Set `PYVISTA_OFF_SCREEN=true` or use `off_screen=True` in Plotter5455## Headless Fallback Pattern5657When the deliverable is an engineering animation/video and the full VTK/PyVista/ParaView rendering path is temporarily unavailable, unstable in the current runtime, or overkill for a first-pass approximation, use a deterministic raw RGB frame pipeline into `ffmpeg`. Keep the artifact clearly labeled as a visualization fallback, not a validated solver output, and verify it with `ffprobe` plus a preview frame before delivery.5859Reference: `references/rawvideo-ffmpeg-headless-fallback.md`6061## Known Issues6263- `cell_quality()` segfaults on tube meshes with VTK 9.6; use deprecated `compute_cell_quality()` until PyVista 0.48+64- First render in a session takes 500-700ms (OpenGL context init); subsequent renders are 35ms6566## Related Skills6768- [blender-interface](../blender/SKILL.md) --- Full 3D scene composition and rendering69- [gmsh-meshing](../gmsh-meshing/SKILL.md) --- Mesh generation for analysis70- [freecad-automation](../freecad-automation/SKILL.md) --- Parametric CAD geometry7172## References7374- PyVista docs: https://docs.pyvista.org/75- PyVista GitHub: https://github.com/pyvista/pyvista76- Evaluation script: `scripts/examples/pyvista_3d_evaluation.py`