/
themes.py
3342 lines (2562 loc) · 97.6 KB
/
themes.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""API description for managing plotting theme parameters in pyvista.
Examples
--------
Apply a built-in theme
>>> import pyvista as pv
>>> pv.set_plot_theme('default')
>>> pv.set_plot_theme('document')
>>> pv.set_plot_theme('dark')
>>> pv.set_plot_theme('paraview')
Load a theme into pyvista
>>> from pyvista.plotting.themes import DocumentTheme
>>> theme = DocumentTheme()
>>> theme.save('my_theme.json') # doctest:+SKIP
>>> loaded_theme = pv.load_theme('my_theme.json') # doctest:+SKIP
Create a custom theme from the default theme and load it into
pyvista.
>>> my_theme = DocumentTheme()
>>> my_theme.font.size = 20
>>> my_theme.font.title_size = 40
>>> my_theme.cmap = 'jet'
>>> pv.global_theme.load_theme(my_theme)
>>> pv.global_theme.font.size
20
"""
from __future__ import annotations
from enum import Enum
from itertools import chain
import json
import os
import pathlib
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
import warnings
import pyvista # noqa: TCH001
from pyvista.core.utilities.misc import _check_range
from .colors import Color, get_cmap_safe, get_cycler
from .opts import InterpolationType
from .tools import parse_font_family
if TYPE_CHECKING: # pragma: no cover
from pyvista.core._typing_core import Number, VectorLike
from ._typing import ColorLike
def _set_plot_theme_from_env() -> None:
"""Set plot theme from an environment variable."""
if 'PYVISTA_PLOT_THEME' in os.environ:
try:
theme = os.environ['PYVISTA_PLOT_THEME']
set_plot_theme(theme.lower())
except ValueError:
allowed = ', '.join([item.name for item in _NATIVE_THEMES])
warnings.warn(
f'\n\nInvalid PYVISTA_PLOT_THEME environment variable "{theme}". '
f'Should be one of the following: {allowed}',
)
def load_theme(filename):
"""Load a theme from a file.
Parameters
----------
filename : str
Theme file. Must be json.
Returns
-------
pyvista.Theme
The loaded theme.
Examples
--------
>>> import pyvista as pv
>>> from pyvista.plotting.themes import DocumentTheme
>>> theme = DocumentTheme()
>>> theme.save('my_theme.json') # doctest:+SKIP
>>> loaded_theme = pv.load_theme('my_theme.json') # doctest:+SKIP
"""
with Path(filename).open() as f:
theme_dict = json.load(f)
return Theme.from_dict(theme_dict)
def 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 as pv
>>> pv.set_plot_theme('default')
Set to the document theme.
>>> pv.set_plot_theme('document')
Set to the dark theme.
>>> pv.set_plot_theme('dark')
Set to the ParaView theme.
>>> pv.set_plot_theme('paraview')
"""
import pyvista
if isinstance(theme, str):
theme = theme.lower()
try:
new_theme_type = _NATIVE_THEMES[theme].value
except KeyError:
raise ValueError(f"Theme {theme} not found in PyVista's native themes.")
pyvista.global_theme.load_theme(new_theme_type())
elif isinstance(theme, Theme):
pyvista.global_theme.load_theme(theme)
else:
raise TypeError(
f'Expected a ``pyvista.plotting.themes.Theme`` or ``str``, not {type(theme).__name__}',
)
# Mostly from https://stackoverflow.com/questions/56579348/how-can-i-force-subclasses-to-have-slots
class _ForceSlots(type):
"""Metaclass to force classes and subclasses to have __slots__."""
@classmethod
def __prepare__(metaclass, name, bases, **kwargs):
super_prepared = super().__prepare__(metaclass, name, bases, **kwargs)
super_prepared['__slots__'] = ()
return super_prepared
class _ThemeConfig(metaclass=_ForceSlots):
"""Provide common methods for theme configuration classes."""
__slots__: List[str] = []
@classmethod
def from_dict(cls, dict_):
"""Create from a dictionary."""
inst = cls()
for key, value in dict_.items():
attr = getattr(inst, key)
if hasattr(attr, 'from_dict'):
setattr(inst, key, attr.from_dict(value))
else:
setattr(inst, key, value)
return inst
def to_dict(self) -> Dict[str, Any]:
"""Return theme config parameters as a dictionary.
Returns
-------
dict
This theme parameter represented as a dictionary.
"""
# remove the first underscore in each entry
dict_ = {}
for key in self._all__slots__():
value = getattr(self, key)
key = key[1:]
if hasattr(value, 'to_dict'):
dict_[key] = value.to_dict()
else:
dict_[key] = value
return dict_
def __eq__(self, other):
if not isinstance(other, _ThemeConfig):
return False
for attr_name in other._all__slots__():
attr = getattr(self, attr_name)
other_attr = getattr(other, attr_name)
if isinstance(attr, (tuple, list)):
if tuple(attr) != tuple(other_attr):
return False
else:
if not attr == other_attr:
return False
return True
def __getitem__(self, key):
"""Get a value via a key.
Implemented here for backwards compatibility.
"""
return getattr(self, key)
def __setitem__(self, key, value):
"""Set a value via a key.
Implemented here for backwards compatibility.
"""
setattr(self, key, value)
@classmethod
def _all__slots__(cls):
"""Get all slots including parent classes."""
mro = cls.mro()
return tuple(chain.from_iterable(c.__slots__ for c in mro if c is not object))
class _LightingConfig(_ThemeConfig):
"""PyVista lighting configuration.
This will control the lighting interpolation type, parameters,
and Physically Based Rendering (PBR) options
Examples
--------
Set global PBR parameters.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.interpolation = 'pbr'
>>> pv.global_theme.lighting_params.metallic = 0.5
>>> pv.global_theme.lighting_params.roughness = 0.25
"""
__slots__ = [
'_interpolation',
'_metallic',
'_roughness',
'_ambient',
'_diffuse',
'_specular',
'_specular_power',
'_emissive',
]
def __init__(self):
self._interpolation = InterpolationType.FLAT.value
self._metallic = 0.0
self._roughness = 0.5
self._ambient = 0.0
self._diffuse = 1.0
self._specular = 0.0
self._specular_power = 100.0
self._emissive = False
@property
def interpolation(self) -> InterpolationType: # numpydoc ignore=RT01
"""Return or set the default interpolation type.
See :class:`pyvista.plotting.opts.InterpolationType`.
Options are:
* ``'Phong'``
* ``'Flat'``
* ``'Physically based rendering'``
This is stored as an integer value of the ``InterpolationType``
so that the theme can be JSON-serializable.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.interpolation = 'Phong'
>>> pv.global_theme.lighting_params.interpolation
<InterpolationType.PHONG: 2>
"""
return InterpolationType.from_any(self._interpolation)
@interpolation.setter
def interpolation(
self,
interpolation: Union[str, int, InterpolationType],
): # numpydoc ignore=GL08
self._interpolation = InterpolationType.from_any(interpolation).value
@property
def metallic(self) -> float: # numpydoc ignore=RT01
"""Return or set the metallic value.
This requires that the interpolation be set to ``'Physically based
rendering'``. Must be between 0 and 1.
Examples
--------
Set the global metallic value used in physically based rendering to
``0.5``.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.metallic = 0.5
>>> pv.global_theme.lighting_params.metallic
0.5
"""
return self._metallic
@metallic.setter
def metallic(self, metallic: float): # numpydoc ignore=GL08
_check_range(metallic, (0, 1), 'metallic')
self._metallic = metallic
@property
def roughness(self) -> float: # numpydoc ignore=RT01
"""Return or set the roughness value.
This value has to be between 0 (glossy) and 1 (rough). A glossy
material has reflections and a high specular part. This parameter is
only used by PBR interpolation.
Examples
--------
Set the global roughness value used in physically based rendering to
``0.25``.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.roughness = 0.25
>>> pv.global_theme.lighting_params.roughness
0.25
"""
return self._roughness
@roughness.setter
def roughness(self, roughness: float): # numpydoc ignore=GL08
_check_range(roughness, (0, 1), 'roughness')
self._roughness = roughness
@property
def ambient(self) -> float: # numpydoc ignore=RT01
"""Return or set the ambient value.
When lighting is enabled, this is the amount of light in the range of 0
to 1 that reaches the actor when not directed at the light source
emitted from the viewer.
Examples
--------
Set the global ambient lighting value to ``0.2``.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.ambient = 0.2
>>> pv.global_theme.lighting_params.ambient
0.2
"""
return self._ambient
@ambient.setter
def ambient(self, ambient: float): # numpydoc ignore=GL08
_check_range(ambient, (0, 1), 'ambient')
self._ambient = ambient
@property
def diffuse(self) -> float: # numpydoc ignore=RT01
"""Return or set the diffuse value.
This is the scattering of light by reflection or
transmission. Diffuse reflection results when light strikes an
irregular surface such as a frosted window or the surface of a
frosted or coated light bulb. Must be between 0 and 1.
Examples
--------
Set the global diffuse lighting value to ``0.5``.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.diffuse = 0.5
>>> pv.global_theme.lighting_params.diffuse
0.5
"""
return self._diffuse
@diffuse.setter
def diffuse(self, diffuse: float): # numpydoc ignore=GL08
_check_range(diffuse, (0, 1), 'diffuse')
self._diffuse = diffuse
@property
def specular(self) -> float: # numpydoc ignore=RT01
"""Return or set the specular value.
Specular lighting simulates the bright spot of a light that appears
on shiny objects. Must be between 0 and 1.
Examples
--------
Set the global specular value to ``0.1``.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.specular = 0.1
>>> pv.global_theme.lighting_params.specular
0.1
"""
return self._specular
@specular.setter
def specular(self, specular: float): # numpydoc ignore=GL08
_check_range(specular, (0, 1), 'specular')
self._specular = specular
@property
def specular_power(self) -> float: # numpydoc ignore=RT01
"""Return or set the specular power value.
Must be between 0.0 and 128.0.
Examples
--------
Set the global specular power value to ``50``.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.specular_power = 50
>>> pv.global_theme.lighting_params.specular_power
50
"""
return self._specular_power
@specular_power.setter
def specular_power(self, specular_power: float): # numpydoc ignore=GL08
_check_range(specular_power, (0, 128), 'specular_power')
self._specular_power = specular_power
@property
def emissive(self) -> bool: # numpydoc ignore=RT01
"""Return or set if emissive is used with point Gaussian style.
Examples
--------
Globally enable emissive lighting when using the point Gaussian style.
>>> import pyvista as pv
>>> pv.global_theme.lighting_params.emissive = True
>>> pv.global_theme.lighting_params.emissive
True
"""
return self._emissive
@emissive.setter
def emissive(self, emissive: bool): # numpydoc ignore=GL08
self._emissive = bool(emissive)
class _DepthPeelingConfig(_ThemeConfig):
"""PyVista depth peeling configuration.
Examples
--------
Set global depth peeling parameters.
>>> import pyvista as pv
>>> pv.global_theme.depth_peeling.number_of_peels = 1
>>> pv.global_theme.depth_peeling.occlusion_ratio = 0.0
>>> pv.global_theme.depth_peeling.enabled = True
"""
__slots__ = ['_number_of_peels', '_occlusion_ratio', '_enabled']
def __init__(self):
self._number_of_peels = 4
self._occlusion_ratio = 0.0
self._enabled = False
@property
def number_of_peels(self) -> int: # numpydoc ignore=RT01
"""Return or set the number of peels in depth peeling.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.depth_peeling.number_of_peels = 1
"""
return self._number_of_peels
@number_of_peels.setter
def number_of_peels(self, number_of_peels: int): # numpydoc ignore=GL08
self._number_of_peels = int(number_of_peels)
@property
def occlusion_ratio(self) -> float: # numpydoc ignore=RT01
"""Return or set the occlusion ratio in depth peeling.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.depth_peeling.occlusion_ratio = 0.0
"""
return self._occlusion_ratio
@occlusion_ratio.setter
def occlusion_ratio(self, occlusion_ratio: float): # numpydoc ignore=GL08
self._occlusion_ratio = float(occlusion_ratio)
@property
def enabled(self) -> bool: # numpydoc ignore=RT01
"""Return or set if depth peeling is enabled.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.depth_peeling.enabled = True
"""
return self._enabled
@enabled.setter
def enabled(self, enabled: bool): # numpydoc ignore=GL08
self._enabled = bool(enabled)
def __repr__(self):
txt = ['']
parm = {
'Number': 'number_of_peels',
'Occlusion ratio': 'occlusion_ratio',
'Enabled': 'enabled',
}
for name, attr in parm.items():
setting = getattr(self, attr)
txt.append(f' {name:<21}: {setting}')
return '\n'.join(txt)
class _SilhouetteConfig(_ThemeConfig):
"""PyVista silhouette configuration.
Examples
--------
Set global silhouette parameters.
>>> import pyvista as pv
>>> pv.global_theme.silhouette.enabled = True
>>> pv.global_theme.silhouette.color = 'grey'
>>> pv.global_theme.silhouette.line_width = 2
>>> pv.global_theme.silhouette.feature_angle = 20
"""
__slots__ = ['_color', '_line_width', '_opacity', '_feature_angle', '_decimate', '_enabled']
def __init__(self):
self._color = Color('black')
self._line_width = 2
self._opacity = 1.0
self._feature_angle = None
self._decimate = None
self._enabled = False
@property
def enabled(self) -> bool: # numpydoc ignore=RT01
"""Return or set whether silhouette is on or off."""
return self._enabled
@enabled.setter
def enabled(self, enabled: bool): # numpydoc ignore=GL08
self._enabled = bool(enabled)
@property
def color(self) -> Color: # numpydoc ignore=RT01
"""Return or set the silhouette color.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.silhouette.color = 'red'
"""
return self._color
@color.setter
def color(self, color: ColorLike): # numpydoc ignore=GL08
self._color = Color(color)
@property
def line_width(self) -> float: # numpydoc ignore=RT01
"""Return or set the silhouette line width.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.silhouette.line_width = 2.0
"""
return self._line_width
@line_width.setter
def line_width(self, line_width: float): # numpydoc ignore=GL08
self._line_width = float(line_width)
@property
def opacity(self) -> float: # numpydoc ignore=RT01
"""Return or set the silhouette opacity.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.silhouette.opacity = 1.0
"""
return self._opacity
@opacity.setter
def opacity(self, opacity: float): # numpydoc ignore=GL08
_check_range(opacity, (0, 1), 'opacity')
self._opacity = float(opacity)
@property
def feature_angle(self) -> Union[float, None]: # numpydoc ignore=RT01
"""Return or set the silhouette feature angle.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.silhouette.feature_angle = 20.0
"""
return self._feature_angle
@feature_angle.setter
def feature_angle(self, feature_angle: Union[float, None]): # numpydoc ignore=GL08
self._feature_angle = feature_angle
@property
def decimate(self) -> float: # numpydoc ignore=RT01
"""Return or set the amount to decimate the silhouette.
Parameter must be between 0 and 1.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.silhouette.decimate = 0.9
"""
return self._decimate
@decimate.setter
def decimate(self, decimate: float): # numpydoc ignore=GL08
if decimate is None:
self._decimate = None
else:
_check_range(decimate, (0, 1), 'decimate')
self._decimate = float(decimate)
def __repr__(self):
txt = ['']
parm = {
'Color': 'color',
'Line width': 'line_width',
'Opacity': 'opacity',
'Feature angle': 'feature_angle',
'Decimate': 'decimate',
}
for name, attr in parm.items():
setting = getattr(self, attr)
txt.append(f' {name:<21}: {setting}')
return '\n'.join(txt)
class _ColorbarConfig(_ThemeConfig):
"""PyVista colorbar configuration.
Examples
--------
Set the colorbar width.
>>> import pyvista as pv
>>> pv.global_theme.colorbar_horizontal.width = 0.2
"""
__slots__ = ['_width', '_height', '_position_x', '_position_y']
def __init__(self):
self._width = None
self._height = None
self._position_x = None
self._position_y = None
@property
def width(self) -> float: # numpydoc ignore=RT01
"""Return or set colorbar width.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.colorbar_horizontal.width = 0.2
"""
return self._width
@width.setter
def width(self, width: float): # numpydoc ignore=GL08
self._width = float(width)
@property
def height(self) -> float: # numpydoc ignore=RT01
"""Return or set colorbar height.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.colorbar_horizontal.height = 0.2
"""
return self._height
@height.setter
def height(self, height: float): # numpydoc ignore=GL08
self._height = float(height)
@property
def position_x(self) -> float: # numpydoc ignore=RT01
"""Return or set colorbar x position.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.colorbar_horizontal.position_x = 0.2
"""
return self._position_x
@position_x.setter
def position_x(self, position_x: float): # numpydoc ignore=GL08
self._position_x = float(position_x)
@property
def position_y(self) -> float: # numpydoc ignore=RT01
"""Return or set colorbar y position.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.colorbar_horizontal.position_y = 0.2
"""
return self._position_y
@position_y.setter
def position_y(self, position_y: float): # numpydoc ignore=GL08
self._position_y = float(position_y)
def __repr__(self):
txt = ['']
parm = {
'Width': 'width',
'Height': 'height',
'X Position': 'position_x',
'Y Position': 'position_y',
}
for name, attr in parm.items():
setting = getattr(self, attr)
txt.append(f' {name:<21}: {setting}')
return '\n'.join(txt)
class _AxesConfig(_ThemeConfig):
"""PyVista axes configuration.
Examples
--------
Set the x axis color to black.
>>> import pyvista as pv
>>> pv.global_theme.axes.x_color = 'black'
Show axes by default.
>>> pv.global_theme.axes.show = True
Use the ``vtk.vtkCubeAxesActor``.
>>> pv.global_theme.axes.box = True
"""
__slots__ = ['_x_color', '_y_color', '_z_color', '_box', '_show']
def __init__(self):
self._x_color = Color('tomato')
self._y_color = Color('seagreen')
self._z_color = Color('mediumblue')
self._box = False
self._show = True
def __repr__(self):
txt = ['Axes configuration']
parm = {
'X Color': 'x_color',
'Y Color': 'y_color',
'Z Color': 'z_color',
'Use Box': 'box',
'Show': 'show',
}
for name, attr in parm.items():
setting = getattr(self, attr)
txt.append(f' {name:<21}: {setting}')
return '\n'.join(txt)
@property
def x_color(self) -> Color: # numpydoc ignore=RT01
"""Return or set x axis color.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.axes.x_color = 'red'
"""
return self._x_color
@x_color.setter
def x_color(self, color: ColorLike): # numpydoc ignore=GL08
self._x_color = Color(color)
@property
def y_color(self) -> Color: # numpydoc ignore=RT01
"""Return or set y axis color.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.axes.y_color = 'red'
"""
return self._y_color
@y_color.setter
def y_color(self, color: ColorLike): # numpydoc ignore=GL08
self._y_color = Color(color)
@property
def z_color(self) -> Color: # numpydoc ignore=RT01
"""Return or set z axis color.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.axes.z_color = 'red'
"""
return self._z_color
@z_color.setter
def z_color(self, color: ColorLike): # numpydoc ignore=GL08
self._z_color = Color(color)
@property
def box(self) -> bool: # numpydoc ignore=RT01
"""Use the ``vtk.vtkCubeAxesActor`` instead of the default ``vtk.vtkAxesActor``.
Examples
--------
>>> import pyvista as pv
>>> pv.global_theme.axes.box = True
"""
return self._box
@box.setter
def box(self, box: bool): # numpydoc ignore=GL08
self._box = bool(box)
@property
def show(self) -> bool: # numpydoc ignore=RT01
"""Show or hide the axes actor.
Examples
--------
Hide the axes by default.
>>> import pyvista as pv
>>> pv.global_theme.axes.show = False
"""
return self._show
@show.setter
def show(self, show: bool): # numpydoc ignore=GL08
self._show = bool(show)
class _Font(_ThemeConfig):
"""PyVista plotter font configuration.
Examples
--------
Set the default font family to 'arial'. Must be either
'arial', 'courier', or 'times'.
>>> import pyvista as pv
>>> pv.global_theme.font.family = 'arial'
Set the default font size to 20.
>>> pv.global_theme.font.size = 20
Set the default title size to 40
>>> pv.global_theme.font.title_size = 40
Set the default label size to 10
>>> pv.global_theme.font.label_size = 10
Set the default text color to 'grey'
>>> pv.global_theme.font.color = 'grey'
Set the string formatter used to format numerical data to '%.6e'
>>> pv.global_theme.font.fmt = '%.6e'
"""
__slots__ = ['_family', '_size', '_title_size', '_label_size', '_color', '_fmt']
def __init__(self):
self._family = 'arial'
self._size = 12
self._title_size = None
self._label_size = None
self._color = Color('white')
self._fmt = None
def __repr__(self):
txt = ['']
parm = {
'Family': 'family',
'Size': 'size',
'Title size': 'title_size',
'Label size': 'label_size',
'Color': 'color',
'Float format': 'fmt',
}
for name, attr in parm.items():
setting = getattr(self, attr)
txt.append(f' {name:<21}: {setting}')
return '\n'.join(txt)
@property
def family(self) -> str: # numpydoc ignore=RT01
"""Return or set the font family.
Must be one of the following:
* ``"arial"``
* ``"courier"``
* ``"times"``
Examples
--------
Set the default global font family to 'courier'.
>>> import pyvista as pv
>>> pv.global_theme.font.family = 'courier'
"""
return self._family
@family.setter
def family(self, family: str): # numpydoc ignore=GL08
parse_font_family(family) # check valid font
self._family = family
@property
def size(self) -> int: # numpydoc ignore=RT01
"""Return or set the font size.
Examples
--------