File: themes.rst

package info (click to toggle)
python-pyvista 0.46.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176,968 kB
  • sloc: python: 94,346; sh: 216; makefile: 70
file content (93 lines) | stat: -rw-r--r-- 2,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
.. _userguide_themes:

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:

.. code-block:: python

   >>> import pyvista
   >>> pyvista.global_theme

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

.. code-block:: python

   >>> pyvista.global_theme.color = 'lightblue'

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

.. pyvista-plot::
   :context:

   >>> import pyvista
   >>> from pyvista import examples
   >>> dragon = examples.download_dragon()
   >>> dragon.plot(cpos='xy')

These parameters can then be modified globally with:

.. pyvista-plot::
   :context:

   >>> 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:

.. pyvista-plot::
   :context:

   >>> dragon.plot(cpos='xy')

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

.. pyvista-plot::
   :context:

   >>> 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:

.. code-block:: python

    # Create a theme based off the DocumentTheme

    my_theme = pyvista.plotting.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:

.. code-block:: python

    my_theme.save('my_theme.json')

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

.. code-block:: python

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


Theme API
---------
See :ref:`theme_api` for the full API definition.