@@ -39,23 +39,26 @@ def is_style_file(filename):
39
39
return STYLE_FILE_PATTERN .match (filename ) is not None
40
40
41
41
42
- def use (name ):
43
- """Use matplotlib style settings from a known style sheet or from a file .
42
+ def use (style ):
43
+ """Use matplotlib style settings from a style specification .
44
44
45
45
Parameters
46
46
----------
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.
47
+ style : str, dict, or list
48
+ str: The name of a style or a path/URL to a style file. For a list of
49
+ available style names, see `style.available`.
50
+ dict: Dictionary with valid key/value pairs in `matplotlib.rcParams`.
51
+ list: List of style specifiers (str or dict) applied from first to
52
+ last in the list.
53
+
53
54
"""
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' ):
56
- name = [name ]
55
+ if cbook .is_string_like (style ) or hasattr (style , 'keys' ):
56
+ # If name is a single str or dict, make it a single element list.
57
+ styles = [style ]
58
+ else :
59
+ styles = style
57
60
58
- for style in name :
61
+ for style in styles :
59
62
if not cbook .is_string_like (style ):
60
63
mpl .rcParams .update (style )
61
64
continue
@@ -74,25 +77,25 @@ def use(name):
74
77
75
78
76
79
@contextlib .contextmanager
77
- def context (name , after_reset = False ):
80
+ def context (style , after_reset = False ):
78
81
"""Context manager for using style settings temporarily.
79
82
80
83
Parameters
81
84
----------
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.
85
+ style : str, dict, or list
86
+ str: The name of a style or a path/URL to a style file. For a list of
87
+ available style names, see `style.available`.
88
+ dict: Dictionary with valid key/value pairs in `matplotlib.rcParams`.
89
+ list: List of style specifiers (str or dict) applied from first to
90
+ last in the list.
88
91
after_reset : bool
89
92
If True, apply style after resetting settings to their defaults;
90
93
otherwise, apply style on top of the current settings.
91
94
"""
92
95
initial_settings = mpl .rcParams .copy ()
93
96
if after_reset :
94
97
mpl .rcdefaults ()
95
- use (name )
98
+ use (style )
96
99
yield
97
100
mpl .rcParams .update (initial_settings )
98
101
0 commit comments