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

Skip to content

Commit c9aff74

Browse files
committed
List to support Path like objects in pyplot.style.use()
1 parent fd3303e commit c9aff74

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

lib/matplotlib/style/core.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,26 @@ def use(style):
8282
| dict | Dictionary with valid key/value pairs for |
8383
| | `matplotlib.rcParams`. |
8484
+------+-------------------------------------------------------------+
85-
| list | A list of style specifiers (str or dict) applied from first |
86-
| | to last in the list. |
87-
+------+-------------------------------------------------------------+
8885
| Path | A Path object which is a path to a style file. |
8986
+------+-------------------------------------------------------------+
87+
| list | A list of style specifiers (str, Path or dict) applied from |
88+
| | first to last in the list. |
89+
+------+-------------------------------------------------------------+
90+
9091
"""
9192
style_alias = {'mpl20': 'default',
9293
'mpl15': 'classic'}
93-
if isinstance(style, str) or hasattr(style, 'keys'):
94-
# If name is a single str or dict, make it a single element list.
94+
if isinstance(style, str) or hasattr(style, 'keys') or \
95+
isinstance(style, Path):
96+
# If name is a single str, Path or dict, make it a single element list.
9597
styles = [style]
96-
elif isinstance(style, Path):
97-
# If the style is pathlib.Path object cast to string.
98-
# and make it a single element list.
99-
styles = [str(style)]
10098
else:
10199
styles = style
102100

103101
styles = (style_alias.get(s, s) if isinstance(s, str) else s
104102
for s in styles)
105103
for style in styles:
106-
if not isinstance(style, str):
104+
if not isinstance(style, str) and not isinstance(style, Path):
107105
_apply_style(style)
108106
elif style == 'default':
109107
# Deprecation warnings were already handled when creating
@@ -113,6 +111,8 @@ def use(style):
113111
elif style in library:
114112
_apply_style(library[style])
115113
else:
114+
if isinstance(style, Path):
115+
style = str(style)
116116
try:
117117
rc = rc_params_from_file(style, use_default_template=False)
118118
_apply_style(rc)

0 commit comments

Comments
 (0)