Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Auto legend cleanup
  • Loading branch information
lukelbd committed Sep 3, 2019
commit 00bd9ffdc3a59f4e6bd77ec5c5e58b4be06b380a
14 changes: 5 additions & 9 deletions proplot/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@ def __init__(self, *args, number=None,
self._altx_child = None
self._alty_parent = None
self._altx_parent = None
self._auto_colorbar = {} # stores plot handles for auto colorbar
self._auto_colorbar = {} # stores handles and kwargs for auto colorbar
self._auto_legend = {}
self._auto_colorbar_kw = {} # keyword args for auto colorbar()
self._auto_legend_kw = {}
# Axis sharing, new text attributes, custom formatting
self._spanx = spanx # boolean toggles, whether we want to span axes labels
self._spany = spany
Expand Down Expand Up @@ -210,14 +208,12 @@ def _draw_auto_legends_colorbars(self):
"""Generate automatic legends and colorbars. Wrapper funcs
let user add handles to location lists with successive calls to
make successive calls to plotting commands."""
for loc,handles in self._auto_colorbar.items():
self.colorbar(handles, **self._auto_colorbar_kw[loc])
for loc,handles in self._auto_legend.items():
self.legend(handles, **self._auto_legend_kw[loc])
for loc,(handles,kwargs) in self._auto_colorbar.items():
self.colorbar(handles, **kwargs)
for loc,(handles,kwargs) in self._auto_legend.items():
self.legend(handles, **kwargs)
self._auto_legend = {}
self._auto_colorbar = {}
self._auto_legend_kw = {}
self._auto_colorbar_kw = {}

def _get_side_axes(self, side):
"""Returns groups of axes in row or column or the single group in the
Expand Down
14 changes: 6 additions & 8 deletions proplot/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,31 +1589,29 @@ def cycle_wrapper(self, func, *args,
if not isinstance(loc, str):
raise ValueError(f'Invalid on-the-fly location {loc!r}. Must be a preset location. See Axes.colorbar')
if loc not in self._auto_colorbar:
self._auto_colorbar[loc] = []
self._auto_colorbar_kw[loc] = {}
self._auto_colorbar[loc].extend(objs)
self._auto_colorbar[loc] = ([], {})
self._auto_colorbar[loc][0].extend(objs)
# Add keywords
if loc != 'fill':
colorbar_kw.setdefault('loc', loc)
if label_leg:
colorbar_kw.setdefault('label', label_leg)
self._auto_colorbar_kw[loc].update(colorbar_kw)
self._auto_colorbar[loc][1].update(colorbar_kw)
if legend:
# Add handles
panel_kw.setdefault('mode', 'legend')
loc = self._loc_translate(legend, **panel_kw)
if not isinstance(loc, str):
raise ValueError(f'Invalid on-the-fly location {loc!r}. Must be a preset location. See Axes.legend')
if loc not in self._auto_legend:
self._auto_legend[loc] = []
self._auto_legend_kw[loc] = {}
self._auto_legend[loc].extend(objs)
self._auto_legend[loc] = ([], {})
self._auto_legend[loc][0].extend(objs)
# Add keywords
if loc != 'fill':
legend_kw.setdefault('loc', loc)
if label_leg:
legend_kw.setdefault('label', label_leg)
self._auto_legend_kw[loc].update(legend_kw)
self._auto_legend[loc][1].update(legend_kw)

# Return
# WARNING: Make sure plot always returns tuple of objects, and bar always
Expand Down