21
21
22
22
import matplotlib as mpl
23
23
from matplotlib import cbook
24
- from matplotlib import rc_params_from_file
24
+ from matplotlib import rc_params_from_file , RcParams
25
25
26
26
27
27
__all__ = ['use' , 'context' , 'available' , 'library' , 'reload_library' ]
@@ -44,16 +44,19 @@ def use(name):
44
44
45
45
Parameters
46
46
----------
47
- name : str or list of str
47
+ name : str, list of str, or RcParams
48
48
Name of style or path/URL to a style file. For a list of available
49
49
style names, see `style.available`. If given a list, each style is
50
- applied from first to last in the list.
50
+ applied from first to last in the list. Instead of strings, each style
51
+ may also be specified directly as an instance of `RcParams`.
51
52
"""
52
- if cbook .is_string_like (name ):
53
+ if cbook .is_string_like (name ) or isinstance ( name , RcParams ) :
53
54
name = [name ]
54
55
55
56
for style in name :
56
- if style in library :
57
+ if isinstance (style , RcParams ):
58
+ mpl .rcParams .update (style )
59
+ elif style in library :
57
60
mpl .rcParams .update (library [style ])
58
61
else :
59
62
try :
@@ -72,10 +75,11 @@ def context(name, after_reset=False):
72
75
73
76
Parameters
74
77
----------
75
- name : str or list of str
78
+ name : str, list of str, or RcParams
76
79
Name of style or path/URL to a style file. For a list of available
77
80
style names, see `style.available`. If given a list, each style is
78
- applied from first to last in the list.
81
+ applied from first to last in the list. Instead of strings, each style
82
+ may also be specified directly as an instance of `RcParams`.
79
83
after_reset : bool
80
84
If True, apply style after resetting settings to their defaults;
81
85
otherwise, apply style on top of the current settings.
0 commit comments