3333USER_LIBRARY_PATHS = [os .path .join (mpl ._get_configdir (), 'stylelib' )]
3434STYLE_EXTENSION = 'mplstyle'
3535STYLE_FILE_PATTERN = re .compile ('([\S]+).%s$' % STYLE_EXTENSION )
36- PARENT_STYLES = 'styles '
36+ PARENT_STYLES = 'style '
3737
3838
3939def 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
7177def 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
114122def 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
118126def get_style_dict (style ):
0 commit comments