21
21
22
22
import matplotlib as mpl
23
23
from matplotlib import cbook
24
- from matplotlib import rc_params_from_file , RcParams
24
+ from matplotlib import rc_params_from_file
25
25
26
26
27
27
__all__ = ['use' , 'context' , 'available' , 'library' , 'reload_library' ]
@@ -44,19 +44,23 @@ def use(name):
44
44
45
45
Parameters
46
46
----------
47
- name : str, list of str, or RcParams
48
- Name of style or path/URL to a style file. For a list of available
49
- style names, see `style.available`. If given a list, each style is
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`.
47
+ name : str, dict, list of str and/or dict
48
+ If `name` is a str, then it is the name of a style or a path/URL to a
49
+ style file. For a list of available style names, see `style.available`.
50
+ If `name` is a dict, then it contains valid rc key/value pairs. If
51
+ `name` is a list of styles, then each style (str or dict) is applied
52
+ from first to last in the list.
52
53
"""
53
- if cbook .is_string_like (name ) or isinstance (name , RcParams ):
54
+ # If name is a single str or dict, make it a single element list.
55
+ if cbook .is_string_like (name ) or hasattr (name , 'keys' ):
54
56
name = [name ]
55
57
56
58
for style in name :
57
- if isinstance ( style , RcParams ):
59
+ if not cbook . is_string_like ( name ):
58
60
mpl .rcParams .update (style )
59
- elif style in library :
61
+ continue
62
+
63
+ if style in library :
60
64
mpl .rcParams .update (library [style ])
61
65
else :
62
66
try :
@@ -75,11 +79,12 @@ def context(name, after_reset=False):
75
79
76
80
Parameters
77
81
----------
78
- name : str, list of str, or RcParams
79
- Name of style or path/URL to a style file. For a list of available
80
- style names, see `style.available`. If given a list, each style is
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`.
82
+ name : str, dict, list of str and/or dict
83
+ If `name` is a str, then it is the name of a style or a path/URL to a
84
+ style file. For a list of available style names, see `style.available`.
85
+ If `name` is a dict, then it contains valid rc key/value pairs. If
86
+ `name` is a list of styles, then each style (str or dict) is applied
87
+ from first to last in the list.
83
88
after_reset : bool
84
89
If True, apply style after resetting settings to their defaults;
85
90
otherwise, apply style on top of the current settings.
0 commit comments