@@ -24,50 +24,51 @@ def _fill_guide_kw(kwargs, overwrite=False, **pairs):
2424 for key , value in pairs .items ():
2525 if value is None :
2626 continue
27- keys = tuple (a for group in aliases for a in group if key in group ) # may be ()
28- if not any (kwargs .get (key ) is not None for key in keys ): # note any(()) is True
29- if overwrite :
30- kwargs [key ] = value
31- else :
32- kwargs .setdefault (key , value )
27+ keys = tuple (k for opts in aliases for k in opts if key in opts )
28+ keys = keys or (key ,) # e.g. 'extend' or something
29+ keys_found = tuple (key for key in keys if kwargs .get (key ) is not None )
30+ if not keys_found :
31+ kwargs [key ] = value
32+ elif overwrite : # overwrite existing key
33+ kwargs [keys_found [0 ]] = value
3334
3435
35- def _guide_kw_from_obj ( obj , name , kwargs ):
36+ def _guide_kw_to_arg ( name , kwargs , ** pairs ):
3637 """
37- Add to the dict from settings stored on the object if there are no conflicts.
38+ Add to the `colorbar_kw` or `legend_kw` dict if there are no conflicts.
3839 """
3940 # WARNING: Here we *do not* want to overwrite properties in the dictionary.
4041 # Indicates e.g. calling colorbar(extend='both') after pcolor(extend='neither').
41- pairs = getattr (obj , f'_{ name } _kw' , None )
42- pairs = pairs or {} # needed for some reason
43- _fill_guide_kw (kwargs , overwrite = False , ** pairs )
44- if isinstance (obj , (tuple , list , np .ndarray )):
45- for iobj in obj : # possibly iterate over matplotlib tuple/list subclasses
46- _guide_kw_from_obj (iobj , name , kwargs )
47- return kwargs
42+ kw = kwargs .setdefault (f'{ name } _kw' , {})
43+ _fill_guide_kw (kw , overwrite = True , ** pairs )
4844
4945
5046def _guide_kw_to_obj (obj , name , kwargs ):
5147 """
52- Add the guide keyword dict to the objects .
48+ Store settings on the object from the input dict .
5349 """
5450 try :
5551 setattr (obj , f'_{ name } _kw' , kwargs )
5652 except AttributeError :
5753 pass
5854 if isinstance (obj , (tuple , list , np .ndarray )):
59- for iobj in obj :
60- _guide_kw_to_obj (iobj , name , kwargs )
55+ for member in obj :
56+ _guide_kw_to_obj (member , name , kwargs )
6157
6258
63- def _guide_kw_to_arg ( name , kwargs , ** pairs ):
59+ def _guide_obj_to_kw ( obj , name , kwargs ):
6460 """
65- Add to the `colorbar_kw` or `legend_kw` dict if there are no conflicts.
61+ Add to the dict from settings stored on the object if there are no conflicts.
6662 """
6763 # WARNING: Here we *do* want to overwrite properties in dictionary. Indicates
6864 # updating kwargs during parsing (probably only relevant for ax.parametric).
69- kw = kwargs .setdefault (f'{ name } _kw' , {})
70- _fill_guide_kw (kw , overwrite = True , ** pairs )
65+ pairs = getattr (obj , f'_{ name } _kw' , None )
66+ pairs = pairs or {} # needed for some reason
67+ _fill_guide_kw (kwargs , overwrite = False , ** pairs )
68+ if isinstance (obj , (tuple , list , np .ndarray )):
69+ for member in obj : # possibly iterate over matplotlib tuple/list subclasses
70+ _guide_obj_to_kw (member , name , kwargs )
71+ return kwargs
7172
7273
7374def _iter_children (* args ):
0 commit comments