get_example

get_example#

get_example(
name: ExampleName | str | Callable[..., Any],
*,
download: bool = True,
) Example[Any, Any][source]#

Look up any example dataset.

Added in version 0.49.

This is a single entry point for every example in pyvista.examples.examples, pyvista.examples.downloads, and pyvista.examples.planets. It returns the example itself – its files, where they come from, and the readers for them – rather than the dataset, which Example.load() reads. Reach for it to work with an example by name, or to get at its files or readers. Type checkers resolve the dataset and reader types from the name, so get_example('cow').load() is a PolyData statically as well as at runtime.

Parameters:
namestr | Callable

Name of the example, such as 'bunny', or the function which returns it, such as examples.download_bunny. A 'download_' or 'load_' prefix on the name is optional.

downloadbool, default: True

Download the example’s files if they are not already present. If False, a FileNotFoundError is raised for any example whose files are missing. Files which are already cached, and examples generated in memory, are unaffected.

Returns:
Example

The example, its files, and its readers.

Examples#

Download Python source code | Download Jupyter notebook

Look up an example and read it.

>>> from pyvista import examples
>>> uniform = examples.get_example('uniform')
>>> mesh = uniform.load()
>>> mesh.n_cells
729

Get the reader PyVista resolves for each file that has one. Most examples have exactly one reader.

>>> [type(reader).__name__ for reader in uniform.readers]
['VTKDataSetReader']

See Also#

Dataset Gallery

Browse every available example.