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

Skip to content

Commit 4239e6c

Browse files
committed
Added tests + dictionnary flattening fixes
1 parent b0279a1 commit 4239e6c

13 files changed

Lines changed: 165 additions & 228 deletions

File tree

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def __call__(self, s):
501501

502502
# a map from key -> value, converter
503503
defaultParams = {
504-
'style': ['', validate_stringlist],
504+
'style': [[''], validate_stringlist],
505505

506506
'backend': ['Agg', validate_backend], # agg is certainly
507507
# present

lib/matplotlib/style/core.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
USER_LIBRARY_PATHS = [os.path.join(mpl._get_configdir(), 'stylelib')]
3434
STYLE_EXTENSION = 'mplstyle'
3535
STYLE_FILE_PATTERN = re.compile('([\S]+).%s$' % STYLE_EXTENSION)
36-
PARENT_STYLES = 'styles'
36+
PARENT_STYLES = 'style'
3737

3838

3939
def is_style_file(filename):
4040
"""Return True if the filename looks like a style file."""
4141
return STYLE_FILE_PATTERN.match(filename) is not None
4242

4343

44-
def use(style):
44+
def use(styles):
4545
"""Use matplotlib style settings from a style specification.
4646
4747
Parameters
@@ -62,11 +62,17 @@ def use(style):
6262
6363
6464
"""
65-
if cbook.is_string_like(style):
66-
# Generate dict from file `style` or from `style` from library
67-
style = get_style_dict(style)
68-
style = flatten_style_dict({PARENT_STYLES: style})
69-
mpl.rcParams.update(style)
65+
if cbook.is_string_like(styles):
66+
styles = [styles]
67+
flattened_style = flatten_style_dict({PARENT_STYLES: styles})
68+
mpl.rcParams.update(flattened_style)
69+
70+
71+
def _expand_parent(parent_style):
72+
if cbook.is_string_like(parent_style):
73+
parent_style = get_style_dict(parent_style)
74+
return parent_style
75+
7076

7177
def flatten_inheritance_dict(child_dict, parent_key,
7278
expand_parent=lambda x: x):
@@ -87,6 +93,8 @@ def flatten_inheritance_dict(child_dict, parent_key,
8793
return child_dict.copy()
8894

8995
parents = child_dict[parent_key]
96+
if isinstance(parents, dict):
97+
parents = [parents]
9098
if not isinstance(parents, (list, tuple)):
9199
msg = "Parent value must be list or tuple, but given {!r}"
92100
raise ValueError(msg.format(parents))
@@ -112,7 +120,7 @@ def flatten_inheritance_dict(child_dict, parent_key,
112120

113121

114122
def flatten_style_dict(style_dict):
115-
return flatten_inheritance_dict(style_dict, PARENT_STYLES)
123+
return flatten_inheritance_dict(style_dict, PARENT_STYLES, expand_parent=_expand_parent)
116124

117125

118126
def get_style_dict(style):

lib/matplotlib/tests/styles/a.mplstyle

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/matplotlib/tests/styles/a1.mplstyle

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/matplotlib/tests/styles/a2.mplstyle

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/matplotlib/tests/styles/b.mplstyle

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/matplotlib/tests/styles/b1.mplstyle

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/matplotlib/tests/styles/b2.mplstyle

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/matplotlib/tests/styles/c.mplstyle

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/matplotlib/tests/styles/c1.mplstyle

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)