Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4621942

Browse files
committed
Allow style.use() to accept RcParams instances.
1 parent a981d54 commit 4621942

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/matplotlib/style/core.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import matplotlib as mpl
2323
from matplotlib import cbook
24-
from matplotlib import rc_params_from_file
24+
from matplotlib import rc_params_from_file, RcParams
2525

2626

2727
__all__ = ['use', 'context', 'available', 'library', 'reload_library']
@@ -44,16 +44,19 @@ def use(name):
4444
4545
Parameters
4646
----------
47-
name : str or list of str
47+
name : str, list of str, or RcParams
4848
Name of style or path/URL to a style file. For a list of available
4949
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`.
5152
"""
52-
if cbook.is_string_like(name):
53+
if cbook.is_string_like(name) or isinstance(name, RcParams):
5354
name = [name]
5455

5556
for style in name:
56-
if style in library:
57+
if isinstance(style, RcParams):
58+
mpl.rcParams.update(style)
59+
elif style in library:
5760
mpl.rcParams.update(library[style])
5861
else:
5962
try:
@@ -72,10 +75,11 @@ def context(name, after_reset=False):
7275
7376
Parameters
7477
----------
75-
name : str or list of str
78+
name : str, list of str, or RcParams
7679
Name of style or path/URL to a style file. For a list of available
7780
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`.
7983
after_reset : bool
8084
If True, apply style after resetting settings to their defaults;
8185
otherwise, apply style on top of the current settings.

0 commit comments

Comments
 (0)