Download and Plot Examples#

Note

This is the solution to Download and Plot Examples. If you haven’t already tried to solve it on your own, you probably should try that first.

Download and plot example datasets.

PyVista contains many downloadable datasets documented at pyvista.examples.downloads. You can download these through Python and then immediately plot them.

This is an easy way to immediately get started with example datasets within PyVista without having to manually download and load them.

Import PyVista and the examples module#

import pyvista as pv
from pyvista import examples

Surface DataSet - Download#

Download a surface dataset of pine roots. Note how the dataset is automatically loaded right into Python.

dataset = examples.download_pine_roots()
dataset
HeaderData Arrays
PolyDataInformation
N Cells351536
N Points178091
N Strips0
X Bounds2.742e+00, 7.847e+01
Y Bounds0.000e+00, 7.969e+01
Z Bounds0.000e+00, 9.961e+01
N Arrays1
NameFieldTypeN CompMinMax
Unnamed_0Pointsfloat323-1.000e+001.000e+00


Surface DataSet - Plot#

Plot the pine roots using PyVista’s default plotting settings.

a load examples solution

Volume DataSet - Download#

Download the bolt dataset. This is an excellent dataset to visualize using “volumetric” plotting.

dataset = examples.download_bolt_nut()
dataset
InformationBlocks
MultiBlockValues
N Blocks2
X Bounds0.000, 69.000
Y Bounds0.000, 122.000
Z Bounds0.000, 65.000
IndexNameType
0boltImageData
1nutImageData


Volume DataSet - Plot#

Here, we plot the dataset using a custom view direction using pyvista.Plotter.

pl = pv.Plotter()
_ = pl.add_volume(
    dataset,
    cmap="coolwarm",
    opacity="sigmoid_5",
    show_scalar_bar=False,
)
pl.camera_position = [(194.6, -141.8, 182.0), (34.5, 61.0, 32.5), (-0.229, 0.45, 0.86)]
pl.show()
a load examples solution

Exercise #1 - Use PyVista Examples#

Visualize one of PyVista’s built in examples.

If your IDE supports it, you should be able to type dataset = examples.download_ and press tab to see all the available examples you can download.

dataset = examples.download_gears()
bodies = dataset.split_bodies()
bodies.plot(
    cmap="jet",
    multi_colors=True,
    smooth_shading=True,
    split_sharp_edges=True,
)
a load examples solution

Exercise #2 - Download and View a File#

Experiment on your own by downloading a dataset and reading it in with pyvista.read. You can use one of your own files or try downloading one from the following sources:

Solution Download the file 'P_shelf_pin.stl' from https://www.thingiverse.com/thing:5412753

mesh = pv.read("P_shelf_pin.stl")
mesh.plot()
a load examples solution
Open In Colab

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

Gallery generated by Sphinx-Gallery