Plotting Themes#

PyVista plotting parameters can be controlled on a plot by plot basis or through a global theme, making it possible to control mesh colors and styles through one global configuration.

See also

Global Configuration

pv.global_theme is one of two global configuration objects. The other, pv.global_config, holds the core non-plotting settings.

The default theme parameters in PyVista can be accessed and displayed with:

>>> import pyvista as pv
>>> pv.global_theme

Default plotting parameters can be accessed individually by their attribute names:

>>> pv.global_theme.color = 'lightblue'

Here’s an example plot of the Stanford Bunny using default plotting parameters:

>>> import pyvista as pv
>>> from pyvista import examples
>>> bunny = examples.download_bunny()
>>> bunny.plot(cpos='xy')
../_images/themes-5cfe6edb5098ade6_00_00.png

These parameters can then be modified globally with:

Now, the mesh will be plotted with the new global parameters:

>>> bunny.plot(cpos='xy')
../_images/themes-a43a65ddc9bfd95e_00_00.png

This is identical to plotting the mesh with the following parameters:

>>> bunny.plot(
...     cpos='xy', color='red', background='white', show_axes=False
... )
../_images/themes-c4f94d7d39479e89_00_00.png

Creating a Custom Theme#

You can customize a theme based on one of the built-in themes and then apply it globally with:

# Create a theme based off the DocumentTheme

my_theme = pv.plotting.themes.DocumentTheme()
my_theme.cmap = 'jet'
my_theme.show_edges = True

# Apply it globally

pv.global_theme.load_theme(my_theme)

Alternatively, you can save the theme to disk to be used later with:

my_theme.save('my_theme.json')

And then subsequently loaded in a new session of pyvista with:

pv.global_theme.load_theme('my_theme.json')

Default Interactor Styles#

Themes can also control the default interactor style used by new plotters. Built-in styles use the same names as the corresponding enable_*_style methods.

import pyvista as pv

pv.global_theme.interactor_style = 'terrain_style'

Custom interactor styles can be registered by downstream packages and used the same way once they are installed or registered at runtime.

Theme API#

See Themes for the full API definition.