Intro to PyVista

I don’t have all that many posts in the gallery yet, so I thought I’d put this very basic introduction to PyVista in here.

PyVista is 3D mesh analysis and visualizaton library in Python. It is capable of handle 3D finite difference/volume spatial data structures with arbitrary geometries. As such, it is capable of representing just about any 3D spatially referenced data set.

In this brief example, I’m going to load a few example meshes, maybe create one from scratch, and visualize them in 3D. (at the moment, this is super basic - I’ll get back to updating this later!).

If you really want to learn more about PyVista, head over to its gallery (I have created many of those examples).

# sphinx_gallery_thumbnail_number = 2
import pyvista as pv
from pyvista import examples

mesh = examples.download_st_helens()
mesh
HeaderData Arrays
UniformGridInformation
N Cells151916
N Points152709
X Bounds5.579e+05, 5.677e+05
Y Bounds5.108e+06, 5.122e+06
Z Bounds6.820e+02, 6.820e+02
Dimensions327, 467, 1
Spacing3.000e+01, 3.000e+01, 1.000e+00
N Arrays1
NameFieldTypeN CompMinMax
ElevationPointsfloat3216.820e+022.543e+03


mesh.plot(cpos='xy')
../_images/sphx_glr_intro-to-pyvista_001.png

Out:

[(562835.0, 5114981.5, 33641.94828749365), (562835.0, 5114981.5, 682.0), (0.0, 1.0, 0.0)]

Here we can apply a filter to alter the mesh: warp it by a scalar attribute, elevation in this case:

topo = mesh.warp_by_scalar()

p = pv.Plotter()
p.add_mesh(topo)
p.show()
../_images/sphx_glr_intro-to-pyvista_002.png

Out:

[(581977.3046422418, 5134123.804642241, 21436.804642241805), (562835.0, 5114981.5, 2294.5), (0.0, 0.0, 1.0)]

Total running time of the script: ( 0 minutes 8.821 seconds)

Gallery generated by Sphinx-Gallery