Skip to content

Commit

Permalink
Cleanup and fix issue passing guide_kw=None
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelbd committed Jan 30, 2022
1 parent d039081 commit 8f8042f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions proplot/axes/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2929,10 +2929,10 @@ def parametric(self, x, y, c, *, interp=0, scalex=True, scaley=True, **kwargs):

# Interpret color values
# NOTE: This permits string label input for 'values'
c, colorbar_kw = inputs._meta_coords(c, which='') # convert string labels
c, guide_kw = inputs._meta_coords(c, which='') # convert string labels
if c.size == 1 and y.size != 1:
c = np.arange(y.size) # convert dummy label for single color
guides._add_guide_kw('colorbar', kw, **colorbar_kw)
guides._add_guide_kw('colorbar', kw, **guide_kw)
guides._add_guide_kw('colorbar', kw, locator=c)

# Interpolate values to allow for smooth gradations between values or just
Expand Down
1 change: 0 additions & 1 deletion proplot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,6 @@ def context(self, *args, mode=0, file=None, **kwargs):
>>> ax.format(ticklen=5, metalinewidth=2)
"""
# Add input dictionaries
# WARNING: Critical to fully apply
for arg in args:
if not isinstance(arg, dict):
raise ValueError(f'Non-dictionary argument {arg!r}.')
Expand Down
17 changes: 11 additions & 6 deletions proplot/internals/guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ def _add_guide_kw(name, kwargs, **opts):
"""
# NOTE: Here we *do not* want to overwrite properties in dictionary. Indicates
# e.g. default locator inferred from levels or default title inferred from metadata.
kwargs = kwargs.setdefault(f'{name}_kw', {})
_update_kw(kwargs, overwrite=False, **opts)
attr = f'{name}_kw'
if not opts:
return
if not kwargs.get(attr, None):
kwargs[attr] = {} # permit e.g. colorbar_kw=None
guide_kw = kwargs[attr]
_update_kw(guide_kw, overwrite=False, **opts)


def _cache_guide_kw(obj, name, kwargs):
Expand Down Expand Up @@ -57,11 +62,11 @@ def _flush_guide_kw(obj, name, kwargs):
# colorbar() because locator or formatter axis would get reset. Old solution was
# to delete the _guide_kw but that destroyed default behavior. New solution is
# to keep _guide_kw but have constructor functions return shallow copies.
opts = getattr(obj, f'_{name}_kw', None)
if opts:
_update_kw(kwargs, overwrite=False, **opts)
guide_kw = getattr(obj, f'_{name}_kw', None)
if guide_kw:
_update_kw(kwargs, overwrite=False, **guide_kw)
for key in REMOVE_AFTER_FLUSH:
opts.pop(key, None)
guide_kw.pop(key, None)
if isinstance(obj, (tuple, list, np.ndarray)):
for member in obj: # possibly iterate over matplotlib tuple/list subclasses
_flush_guide_kw(member, name, kwargs)
Expand Down

0 comments on commit 8f8042f

Please sign in to comment.