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.

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

import pyvista
pyvista.global_theme
Default Theme
-------------
Background               : [0.3, 0.3, 0.3]
Jupyter backend          : static
Full screen              : False
Window size              : [1024, 768]
Camera                   : {'position': [1, 1, 1], 'viewup': [0, 0, 1]}
Notebook                 : None
Font                     : 
    Family               : arial
    Size                 : 12
    Title size           : None
    Label size           : None
    Color                : [1, 1, 1]
    Float format         : None
Auto close               : True
Colormap                 : viridis
Color                    : (1.0, 1.0, 1.0)
NaN color                : (0.6627450980392157, 0.6627450980392157, 0.6627450980392157)
Edge color               : (0.0, 0.0, 0.0)
Outline color            : (1.0, 1.0, 1.0)
Floor color              : (0.5019607843137255, 0.5019607843137255, 0.5019607843137255)
Colorbar orientation     : horizontal
Colorbar - horizontal    : 
    Width                : 0.6
    Height               : 0.08
    X Position           : 0.35
    Y Position           : 0.05
Colorbar - vertical      : 
    Width                : 0.08
    Height               : 0.45
    X Position           : 0.9
    Y Position           : 0.02
Show scalar bar          : True
Show edges               : False
Lighting                 : True
Interactive              : False
Render points as spheres : False
Transparent Background   : False
Title                    : PyVista
Axes                     : Axes configuration
    X Color              : (1.0, 0.38823529411764707, 0.2784313725490196)
    Y Color              : (0.1803921568627451, 0.5450980392156862, 0.3411764705882353)
    Z Color              : (0.0, 0.0, 0.803921568627451)
    Use Box              : False
    Show                 : True
Multi-samples            : 4
Multi-renderer Split Pos : None
Volume mapper            : smart
Smooth shading           : False
Depth peeling            : 
    Number               : 4
    Occlusion ratio      : 0.0
    Enabled              : False
Silhouette               : 
    Color                : (0.0, 0.0, 0.0)
    Line width           : 2
    Opacity              : 1.0
    Feature angle        : None
    Decimate             : 0.9
Slider Styles            : 
    Classic              : 
        Slider length    : 0.02
        Slider width     : 0.04
        Slider color     : (0.5, 0.5, 0.5)
        Tube width       : 0.005
        Tube color       : (1, 1, 1)
        Cap opacity      : 1.0
        Cap length       : 0.01
        Cap width        : 0.02
    Modern               : 
        Slider length    : 0.02
        Slider width     : 0.04
        Slider color     : (0.43137255, 0.44313725, 0.45882353)
        Tube width       : 0.04
        Tube color       : (0.69803922, 0.70196078, 0.70980392)
        Cap opacity      : 0.0
        Cap length       : 0.01
        Cap width        : 0.02

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

pyvista.global_theme.color
(1.0, 1.0, 1.0)

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

from pyvista import examples
dragon = examples.download_dragon()
dragon.plot(cpos='xy')
../_images/themes_3_0.png

These parameters can then be modified globally with:

pyvista.global_theme.color = 'red'
pyvista.global_theme.background = 'white'
pyvista.global_theme.axes.show = False

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

dragon.plot(cpos='xy')
../_images/themes_5_0.png

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

dragon.plot(cpos='xy', color='red', background='white', show_axes=False)

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 = pyvista.themes.DocumentTheme()
my_theme.cmap = 'jet'
my_theme.show_edges = True

# apply it globally
pyvista.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:

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

Theme API

API description for managing plotting theme parameters in pyvista.

Examples

Apply a built-in theme

>>> import pyvista
>>> pyvista.set_plot_theme('default')
>>> pyvista.set_plot_theme('document')
>>> pyvista.set_plot_theme('dark')
>>> pyvista.set_plot_theme('paraview')

Load a theme into pyvista

>>> theme = pyvista.themes.DefaultTheme()
>>> theme.save('my_theme.json')  
>>> loaded_theme = pyvista.load_theme('my_theme.json')  

Create a custom theme from the default theme and load it into pyvista.

>>> my_theme = pyvista.themes.DefaultTheme()
>>> my_theme.font.size = 20
>>> my_theme.font.title_size = 40
>>> my_theme.cmap = 'jet'
...
>>> pyvista.global_theme.load_theme(my_theme)
>>> pyvista.global_theme.font.size
20
class pyvista.themes.DarkTheme

Dark mode theme.

Black background, “viridis” colormap, tan meshes, white (hidden) edges.

Examples

Make the dark theme the global default.

>>> import pyvista
>>> from pyvista import themes
>>> pyvista.set_plot_theme(themes.DarkTheme())

Alternatively, set via a string.

>>> pyvista.set_plot_theme('dark')
class pyvista.themes.DefaultTheme

PyVista default theme.

Examples

Change the global default background color to white.

>>> import pyvista
>>> pyvista.global_theme.color = 'white'

Show edges by default.

>>> pyvista.global_theme.show_edges = True

Create a new theme from the default theme and apply it globally.

>>> my_theme = pyvista.themes.DefaultTheme()
>>> my_theme.color = 'red'
>>> my_theme.background = 'white'
>>> pyvista.global_theme.load_theme(my_theme)
property auto_close: bool

Automatically close the figures when finished plotting.

Danger

Set to False with extreme caution.

Examples

>>> import pyvista
>>> pyvista.global_theme.auto_close = False
property axes: pyvista.themes._AxesConfig

Return or set the default axes configuration.

Examples

Set the x axis color to black.

>>> import pyvista
>>> pyvista.global_theme.axes.x_color = 'black'

Show axes by default.

>>> pyvista.global_theme.axes.show = True

Use the vtk.vtkCubeAxesActor.

>>> pyvista.global_theme.axes.box = True
property background

Return or set the default background color of pyvista plots.

Examples

Set the default global background of all plots to white.

>>> import pyvista
>>> pyvista.global_theme.background = 'white'
property camera

Return or set the default camera position.

Examples

Set both the position and view of the camera.

>>> import pyvista
>>> pyvista.global_theme.camera = {'position': [1, 1, 1],
...                                'viewup': [0, 0, 1]}

Set the default position of the camera.

>>> pyvista.global_theme.camera['position'] = [1, 1, 1]

Set the default view of the camera.

>>> pyvista.global_theme.camera['viewup'] = [0, 0, 1]
property cmap

Return or set the default colormap of pyvista.

See available Matplotlib colormaps. Only applicable for when displaying scalars. Requires Matplotlib to be installed. If colorcet or cmocean are installed, their colormaps can be specified by name.

You can also specify a list of colors to override an existing colormap with a custom one. For example, to create a three color colormap you might specify ['green', 'red', 'blue']

Examples

Set the default global colormap to ‘jet’.

>>> import pyvista
>>> pyvista.global_theme.cmap = 'jet'
property color: tuple

Return or set the default color of meshes in pyvista.

Used for meshes without scalars.

When setting, the value must be either a string, rgb list, or hex color string. For example:

  • color='white'

  • color='w'

  • color=[1, 1, 1]

  • color='#FFFFFF'

Examples

Set the default mesh color to ‘red’.

>>> import pyvista
>>> pyvista.global_theme.color = 'red'
property colorbar_horizontal: pyvista.themes._ColorbarConfig

Return or set the default parameters of a horizontal colorbar.

Examples

Set the default horizontal colorbar width to 0.6.

>>> import pyvista
>>> pyvista.global_theme.colorbar_horizontal.width = 0.6

Set the default horizontal colorbar height to 0.2.

>>> pyvista.global_theme.colorbar_horizontal.height = 0.2
property colorbar_orientation: str

Return or set the default colorbar orientation.

Must be either 'vertical' or 'horizontal'.

Examples

>>> import pyvista
>>> pyvista.global_theme.colorbar_orientation = 'horizontal'
property colorbar_vertical: pyvista.themes._ColorbarConfig

Return or set the default parameters of a vertical colorbar.

Examples

Set the default colorbar width to 0.45.

>>> import pyvista
>>> pyvista.global_theme.colorbar_vertical.width = 0.45

Set the default colorbar height to 0.8.

>>> import pyvista
>>> pyvista.global_theme.colorbar_vertical.height = 0.8
property depth_peeling: pyvista.themes._DepthPeelingConfig

Return or set the default depth peeling parameters.

Examples

Set the global depth_peeling parameter default to be enabled with 8 peels.

>>> import pyvista
>>> pyvista.global_theme.depth_peeling.number_of_peels = 8
>>> pyvista.global_theme.depth_peeling.occlusion_ratio = 0.0
>>> pyvista.global_theme.depth_peeling.enabled = True
property edge_color: tuple

Return or set the default edge color.

Examples

Set the global edge color to ‘blue’.

>>> import pyvista
>>> pyvista.global_theme.edge_color = 'blue'
property floor_color: tuple

Return or set the default floor color.

Examples

>>> import pyvista
>>> pyvista.global_theme.floor_color = 'black'
property font: pyvista.themes._Font

Return or set the default font size, family, and/or color.

Examples

Set the default font family to ‘arial’. Must be either ‘arial’, ‘courier’, or ‘times’.

>>> import pyvista
>>> pyvista.global_theme.font.family = 'arial'

Set the default font size to 20.

>>> pyvista.global_theme.font.size = 20

Set the default title size to 40.

>>> pyvista.global_theme.font.title_size = 40

Set the default label size to 10.

>>> pyvista.global_theme.font.label_size = 10

Set the default text color to ‘grey’.

>>> pyvista.global_theme.font.color = 'grey'

String formatter used to format numerical data to ‘%.6e’.

>>> pyvista.global_theme.font.fmt = '%.6e'
property full_screen: bool

Return if figures are shown in full screen.

Examples

Set windows to be full screen by default.

>>> import pyvista
>>> pyvista.global_theme.full_screen = True
property interactive: bool

Return or set the default interactive parameter.

Examples

Make all plots non-interactive globally.

>>> import pyvista
>>> pyvista.global_theme.interactive = False
property jupyter_backend: str

Return or set the jupyter notebook plotting backend.

Jupyter backend to use when plotting. Must be one of the following:

  • 'ipyvtklink' : Render remotely and stream the resulting VTK images back to the client. Supports all VTK methods, but suffers from lag due to remote rendering. Requires that a virtual framebuffer be setup when displaying on a headless server. Must have ipyvtklink installed.

  • 'panel' : Convert the VTK render window to a vtkjs object and then visualize that within jupyterlab. Supports most VTK objects. Requires that a virtual framebuffer be setup when displaying on a headless server. Must have panel installed.

  • 'ipygany' : Convert all the meshes into ipygany meshes and streams those to be rendered on the client side. Supports VTK meshes, but few others. Aside from none, this is the only method that does not require a virtual framebuffer. Must have ipygany installed.

  • 'static' : Display a single static image within the JupyterLab environment. Still requires that a virtual framebuffer be setup when displaying on a headless server, but does not require any additional modules to be installed.

  • 'none' : Do not display any plots within jupyterlab, instead display using dedicated VTK render windows. This will generate nothing on headless servers even with a virtual framebuffer.

Examples

Enable the ipygany backend.

>>> import pyvista as pv
>>> pv.set_jupyter_backend('ipygany')

Enable the panel backend.

>>> pv.set_jupyter_backend('panel')

Enable the ipyvtklink backend.

>>> pv.set_jupyter_backend('ipyvtklink')

Just show static images.

>>> pv.set_jupyter_backend('static')

Disable all plotting within JupyterLab and display using a standard desktop VTK render window.

>>> pv.set_jupyter_backend(None)  # or 'none'
property lighting: bool

Return or set the default lighting.

Examples

Disable lighting globally.

>>> import pyvista
>>> pyvista.global_theme.lighting = False
load_theme(theme)

Overwrite the current theme with a theme.

Examples

Create a custom theme from the default theme and load it into the global theme of pyvista.

>>> import pyvista
>>> from pyvista.themes import DefaultTheme
>>> my_theme = DefaultTheme()
>>> my_theme.font.size = 20
>>> my_theme.font.title_size = 40
>>> my_theme.cmap = 'jet'
...
>>> pyvista.global_theme.load_theme(my_theme)
>>> pyvista.global_theme.font.size
20

Create a custom theme from the dark theme and load it into pyvista.

>>> from pyvista.themes import DarkTheme
>>> my_theme = DarkTheme()
>>> my_theme.show_edges = True
>>> pyvista.global_theme.load_theme(my_theme)
>>> pyvista.global_theme.show_edges
True
property multi_rendering_splitting_position: float

Return or set the default multi_rendering_splitting_position parameter.

Examples

Set multi_rendering_splitting_position globally to 0.5 (the middle of the window).

>>> import pyvista
>>> pyvista.global_theme.multi_rendering_splitting_position = 0.5
property multi_samples: int

Return or set the default multi_samples parameter.

Set the number of multisamples to enable hardware antialiasing.

Examples

Set the default number of multisamples to 2.

>>> import pyvista
>>> pyvista.global_theme.multi_samples = 2
property name: str

Return or set the name of the theme.

property nan_color: tuple

Return or set the default NaN color.

This color is used to plot all NaN values.

Examples

>>> import pyvista
>>> pyvista.global_theme.nan_color = 'darkgray'
property notebook: Optional[bool]

Return or set the state of notebook plotting.

Setting this to True always enables notebook plotting, while setting it to False disables plotting even when plotting within a jupyter notebook and plots externally.

Examples

Disable all jupyter notebook plotting.

>>> import pyvista
>>> pyvista.global_theme.notebook = False
property outline_color: tuple

Return or set the default outline color.

Examples

>>> import pyvista
>>> pyvista.global_theme.outline_color = 'white'
property render_points_as_spheres: bool

Return or set the default render_points_as_spheres parameter.

Examples

Render points as spheres by default globally.

>>> import pyvista
>>> pyvista.global_theme.render_points_as_spheres = True
restore_defaults()

Restore the theme defaults.

Examples

>>> import pyvista
>>> pyvista.global_theme.restore_defaults()
save(filename)

Serialize this theme to a json file.

Examples

Export and then load back in a theme.

>>> import pyvista
>>> theme = pyvista.themes.DefaultTheme()
>>> theme.background = 'white'
>>> theme.save('my_theme.json')  
>>> loaded_theme = pyvista.load_theme('my_theme.json')  
property show_edges: bool

Return or set the default edge visibility.

Examples

Show edges globally by default.

>>> import pyvista
>>> pyvista.global_theme.show_edges = True
property show_scalar_bar: bool

Return or set the default color bar visibility.

Examples

Show the scalar bar by default when scalars are available.

>>> import pyvista
>>> pyvista.global_theme.show_scalar_bar = True
property silhouette: pyvista.themes._SilhouetteConfig

Return or set the default silhouette configuration.

Examples

Set parameters of the silhouette.

>>> import pyvista
>>> pyvista.global_theme.silhouette.color = 'grey'
>>> pyvista.global_theme.silhouette.line_width = 2.0
>>> pyvista.global_theme.silhouette.feature_angle = 20
property slider_styles: pyvista.themes._SliderConfig

Return the default slider style configurations.

property smooth_shading: bool

Return or set the default smooth_shading parameter.

Examples

Set the global smooth_shading parameter default to True.

>>> import pyvista
>>> pyvista.global_theme.smooth_shading = True
property title: str

Return or set the default title parameter.

This is the VTK render window title.

Examples

Set title globally to ‘plot’.

>>> import pyvista
>>> pyvista.global_theme.title = 'plot'
property transparent_background: bool

Return or set the default transparent_background parameter.

Examples

Set transparent_background globally to True.

>>> import pyvista
>>> pyvista.global_theme.transparent_background = True
property use_ipyvtk

Set or return the usage of “ipyvtk” as a jupyter backend.

Deprecated in favor of jupyter_backend.

property volume_mapper: str

Return or set the default volume_mapper parameter.

Must be one of the following strings, which are mapped to the following VTK volume mappers.

  • 'fixed_point' : vtk.vtkFixedPointVolumeRayCastMapper

  • 'gpu' : vtk.vtkGPUVolumeRayCastMapper

  • 'open_gl' : vtk.vtkOpenGLGPUVolumeRayCastMapper

  • 'smart' : vtk.vtkSmartVolumeMapper

Examples

Set default volume mapper globally to ‘gpu’.

>>> import pyvista
>>> pyvista.global_theme.volume_mapper = 'gpu'
property window_size: List[int]

Return or set the default render window size.

Examples

Set window size to [400, 400].

>>> import pyvista
>>> pyvista.global_theme.window_size = [400, 400]
class pyvista.themes.DocumentTheme

A document theme well suited for papers and presentations.

This theme uses a white background, black fonts, the “viridis” colormap, and it disables edges. Best used for presentations, papers, etc.

Examples

Make the document theme the global default.

>>> import pyvista
>>> from pyvista import themes
>>> pyvista.set_plot_theme(themes.DocumentTheme())

Alternatively, set via a string.

>>> pyvista.set_plot_theme('document')
class pyvista.themes.ParaViewTheme

A paraview-like theme.

Examples

Make the paraview-like theme the global default.

>>> import pyvista
>>> from pyvista import themes
>>> pyvista.set_plot_theme(themes.ParaViewTheme())

Alternatively, set via a string.

>>> pyvista.set_plot_theme('paraview')
pyvista.themes.load_theme(filename)

Load a theme from a file.

Examples

>>> import pyvista
>>> theme = pyvista.themes.DefaultTheme()
>>> theme.save('my_theme.json')  
>>> loaded_theme = pyvista.load_theme('my_theme.json')  
pyvista.themes.set_plot_theme(theme)

Set the plotting parameters to a predefined theme using a string.

Parameters

theme (str) – Theme name. Either 'default', 'document', 'dark', or 'paraview'.

Examples

Set to the default theme.

>>> import pyvista
>>> pyvista.set_plot_theme('default')

Set to the document theme.

>>> pyvista.set_plot_theme('document')

Set to the dark theme.

>>> pyvista.set_plot_theme('dark')

Set to the ParaView theme.

>>> pyvista.set_plot_theme('paraview')