Skip to content

Commit

Permalink
Further sync axes_grid colorbars with standard colorbars.
Browse files Browse the repository at this point in the history
Remap the cbid and locator attributes to the ones of standard colorbars.
Move most functionality of CbarAxes to CbarAxesBase, leaving only the
multiple-inheritance part, so that axisartist.axes_grid.CbarAxes can
likewise just limit itself to multiple-inheritance.
  • Loading branch information
anntzer committed Apr 30, 2020
1 parent 0e900cf commit 1163bf5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
5 changes: 5 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,8 @@ experimental and may change in the future.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These are unused and can be easily reproduced by other date tools.
`.get_epoch` will return Matplotlib's epoch.

``axes_grid1.CbarAxes`` attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``cbid`` and ``locator`` attribute are deprecated. Use
``mappable.colorbar_cid`` and ``colorbar.locator``, as for standard colorbars.
48 changes: 29 additions & 19 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def _tick_only(ax, bottom_on, left_on):


class CbarAxesBase:
def __init__(self, *args, orientation, **kwargs):
self.orientation = orientation
self._default_label_on = True
self._locator = None # deprecated.
super().__init__(*args, **kwargs)

@cbook._rename_parameter("3.2", "locator", "ticks")
def colorbar(self, mappable, *, ticks=None, **kwargs):
Expand All @@ -38,21 +43,30 @@ def colorbar(self, mappable, *, ticks=None, **kwargs):
if ticks is None:
ticks = ticker.MaxNLocator(5) # For backcompat.
from .colorbar import Colorbar
cb = Colorbar(
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
self._cbid = mappable.callbacksSM.connect(
'changed', cb.update_normal)
mappable.colorbar = cb
self._locator = cb.cbar_axis.get_major_locator()
else:
from matplotlib.colorbar import Colorbar
cb = Colorbar(
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
self._config_axes()
cb = mpl.colorbar.colorbar_factory(
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
self._cbid = mappable.colorbar_cid # deprecated.
self._locator = cb.locator # deprecated.

self.cbid = mappable.callbacksSM.connect('changed', cb.update_normal)
mappable.colorbar = cb
self._config_axes()
return cb

if mpl.rcParams["mpl_toolkits.legacy_colorbar"]:
self.locator = cb.cbar_axis.get_major_locator()
else:
self.locator = cb.locator
@cbook.deprecated("3.3", alternative="mappable.colorbar_cid")
@property
def cbid(self):
return self._cbid

return cb
@cbook.deprecated("3.3", alternative=".colorbar().locator")
@property
def locator(self):
return self._locator

def _config_axes(self):
"""Make an axes patch and outline."""
Expand All @@ -67,19 +81,15 @@ def toggle_label(self, b):
axis = self.axis[self.orientation]
axis.toggle(ticklabels=b, label=b)


class CbarAxes(CbarAxesBase, Axes):
def __init__(self, *args, orientation, **kwargs):
self.orientation = orientation
self._default_label_on = True
self.locator = None
super().__init__(*args, **kwargs)

def cla(self):
super().cla()
self._config_axes()


class CbarAxes(CbarAxesBase, Axes):
pass


class Grid:
"""
A grid of Axes.
Expand Down
10 changes: 1 addition & 9 deletions lib/mpl_toolkits/axisartist/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@


class CbarAxes(axes_grid_orig.CbarAxesBase, Axes):
def __init__(self, *args, orientation, **kwargs):
self.orientation = orientation
self._default_label_on = False
self.locator = None
super().__init__(*args, **kwargs)

def cla(self):
super().cla()
self._config_axes()
pass


class Grid(axes_grid_orig.Grid):
Expand Down

0 comments on commit 1163bf5

Please sign in to comment.