Examples#

PyVista contains a variety of built-in demos and downloadable example datasets. For example:

Plot the built-in hills dataset

>>> from pyvista import examples
>>> hills = examples.load_random_hills()
>>> hills.plot()
../../_images/index-1_00_00.png

Many datasets are too large to be included with PyVista, but can be downloaded and cached locally. These datasets can be downloaded and used with:

Plot the turbine blade mesh.

>>> from pyvista import examples
>>> blade_mesh = examples.download_turbine_blade()
>>> blade_mesh.plot()
../../_images/index-2_00_00.png

Finally, PyVista contains some demos which can be used to quickly demonstrate features.

Create and show the orientation cube plotter

>>> from pyvista import demos
>>> plotter = demos.orientation_plotter()
>>> plotter.show()
../../_images/index-3_00_00.png

API Reference#

examples.examples

Built-in examples that ship with PyVista and do not need to be downloaded.

examples.downloads

Downloadable datasets collected from various sources.

examples.planets

Downloadable datasets of 3D Celestial Bodies.

examples.vrml

Contains vrml examples.

examples.download_3ds

Contains 3ds examples.

demos.demos

Demos to show off the functionality of PyVista.

Usage Considerations#

Warning

As you browse this repository and think about how you might use our 3D models and range datasets, please remember that several of these artifacts have religious or cultural significance. Examples include the Buddha, a religious symbol revered by hundreds of millions of people; the dragon, a symbol of Chinese culture, the Thai statue, which contains elements of religious significance to Hindus; and Lucy, a Christian angel commonly seen as statues in Italian churches. Keep your renderings and other uses of these particular models in good taste. Don’t animate or morph them, don’t apply Boolean operators to them, and don’t simulate nasty things happening to them (like breaking, exploding, melting, etc.). Choose another model for these sorts of experiments. (You can do anything you want to the Stanford bunny or the armadillo.)

Downloads Cache and Data Sources#

If you have an internet connection and a normal user account, PyVista should be able to download and cache examples without an issue. The following two sections deal with those who wish to customize how PyVista downloads examples.

Cache#

PyVista uses pooch to download and store the example files in a local cache. You can determine the location of this cache at runtime with:

>>> from pyvista import examples
>>> # Get the local examples path on Linux
>>> examples.PATH
'/home/user/.cache/pyvista_3'

You can clear out the local cache with examples.delete_downloads() if needed.

If you want to override this local cache path, set the PYVISTA_USERDATA_PATH environment variable. This path must be writable.

Data Sources#

PyVista uses PyVista/vtk-data as the main source for example data. If you do not have internet access or you prefer using a local or network directory instead, you can override this source with the VTK_DATA_PATH environment variable.

The following example first clones the git repository and then exports that directory to PyVista via VTK_DATA_PATH. Note how the path ends in 'Data' since we need to specify the exact directory of the Data for pooch.

git clone https://github.com/pyvista/vtk-data.git
export VTK_DATA_PATH=/home/alex/python/vtk-data/Data

Cells#

PyVista contains several functions that create single cell pyvista.UnstructuredGrid objects that can be used to learn about VTK cell types.

plot_cell(grid[, cpos])

Plot a pyvista.UnstructuredGrid while displaying cell indices.

Empty()

Create a pyvista.UnstructuredGrid containing a single empty cell.

Vertex()

Create a pyvista.UnstructuredGrid containing a single Vertex.

PolyVertex()

Create a pyvista.UnstructuredGrid containing a single poly vertex.

Line()

Create a pyvista.UnstructuredGrid containing a single Line.

PolyLine()

Create a pyvista.UnstructuredGrid containing a single poly line.

Triangle()

Create a pyvista.UnstructuredGrid containing a single Triangle.

TriangleStrip()

Create a pyvista.UnstructuredGrid containing a single triangle strip.

Polygon()

Create a pyvista.UnstructuredGrid containing a single polygon.

Quadrilateral()

Create a pyvista.UnstructuredGrid containing a single quadrilateral.

Tetrahedron()

Create a pyvista.UnstructuredGrid containing a single Tetrahedron.

Voxel()

Create a pyvista.UnstructuredGrid containing a single voxel.

Hexahedron()

Create a pyvista.UnstructuredGrid containing a single hexahedron.

Wedge()

Create a pyvista.UnstructuredGrid containing a single wedge.

Pyramid()

Create a pyvista.UnstructuredGrid containing a single pyramid.

PentagonalPrism()

Create a pyvista.UnstructuredGrid containing a single pentagonal prism.

HexagonalPrism()

Create a pyvista.UnstructuredGrid containing a single hexagonal prism.