8000 Further sync axes_grid colorbars with standard colorbars. · matplotlib/matplotlib@1163bf5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1163bf5

Browse files
committed
Further sync axes_grid colorbars with standard colorbars.
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.
1 parent 0e900cf commit 1163bf5

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

doc/api/api_changes_3.3/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,8 @@ experimental and may change in the future.
515515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
516516
These are unused and can be easily reproduced by other date tools.
517517
`.get_epoch` will return Matplotlib's epoch.
518+
519+
``axes_grid1.CbarAxes`` attributes
520+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
521+
The ``cbid`` and ``locator`` attribute are deprecated. Use
522+
``mappable.colorbar_cid`` and ``colorbar.locator``, as for standard colorbars.

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def _tick_only(ax, bottom_on, left_on):
1919

2020

2121
class CbarAxesBase:
22+
def __init__(self, *args, orientation, **kwargs):
23+
self.orientation = orientation
24+
self._default_label_on = True
25+
self._locator = None # deprecated.
26+
super().__init__(*args, **kwargs)
2227

2328
@cbook._rename_parameter("3.2", "locator", "ticks")
2429
def colorbar(self, mappable, *, ticks=None, **kwargs):
@@ -38,21 +43,30 @@ def colorbar(self, mappable, *, ticks=None, **kwargs):
3843
if ticks is None:
3944
ticks = ticker.MaxNLocator(5) # For backcompat.
4045
from .colorbar import Colorbar
46+
cb = Colorbar(
47+
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
48+
self._cbid = mappable.callbacksSM.connect(
49+
'changed', cb.update_normal)
50+
mappable.colorbar = cb
51+
self._locator = cb.cbar_axis.get_major_locator()
4152
else:
42-
from matplotlib.colorbar import Colorbar
43-
cb = Colorbar(
44-
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
45-
self._config_axes()
53+
cb = mpl.colorbar.colorbar_factory(
54+
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
55+
self._cbid = mappable.colorbar_cid # deprecated.
56+
self._locator = cb.locator # deprecated.
4657

47-
self.cbid = mappable.callbacksSM.connect('changed', cb.update_normal)
48-
mappable.colorbar = cb
58+
self._config_axes()
59+
return cb
4960

50-
if mpl.rcParams["mpl_toolkits.legacy_colorbar"]:
51-
self.locator = cb.cbar_axis.get_major_locator()
52-
else:
53-
self.locator = cb.locator
61+
@cbook.deprecated("3.3", alternative="mappable.colorbar_cid")
62+
@property
63+
def cbid(self):
64+
return self._cbid
5465

55-
return cb
66+
@cbook.deprecated("3.3", alternative=".colorbar().locator")
67+
@property
68+
def locator(self):
69+
return self._locator
5670

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

70-
71-
class CbarAxes(CbarAxesBase, Axes):
72-
def __init__(self, *args, orientation, **kwargs):
73-
self.orientation = orientation
74-
self._default_label_on = True
75-
self.locator = None
76-
super().__init__(*args, **kwargs)
77-
7884
def cla(self):
7985
super().cla()
8086
self._config_axes()
8187

8288

89+
class CbarAxes(CbarAxesBase, Axes):
90+
pass
91+
92+
8393
class Grid:
8494
"""
8595
A grid of Axes.

lib/mpl_toolkits/axisartist/axes_grid.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33

44

55
class CbarAxes(axes_grid_orig.CbarAxesBase, Axes):
6-
def __init__(self, *args, orientation, **kwargs):
7-
self.orientation = orientation
8-
self._default_label_on = False
9-
self.locator = None
10-
super().__init__(*args, **kwargs)
11-
12-
def cla(self):
13-
super().cla()
14-
self._config_axes()
6+
pass
157

168

179
class Grid(axes_grid_orig.Grid):

0 commit comments

Comments
 (0)
0