Skip to content

Commit 148ed82

Browse files
committed
Merge pull request #2055 from pelson/mappable_colorbar_attribute
Deprecated the set_colorbar method on a scalar mappable.
2 parents d5071f4 + 785d66a commit 148ed82

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

doc/api/api_changes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ Changes in 1.3.x
117117
position type. Previously, it would draw the right or top spine at
118118
+1 data offset.
119119

120+
* The ScalarMappable class' set_colorbar is now deprecated. Instead, the
121+
:attr:`matplotlib.cm.ScalarMappable.colorbar` attribute should be used.
122+
In previous matplotlib versions this attribute was an undocumented tuple
123+
of ``(colorbar_instance, colorbar_axes)`` but is now just
124+
``colorbar_instance``. To get the colorbar axes it is possible to just use
125+
the :attr:`~matplotlib.colorbar.ColorbarBase.ax` attribute on a colorbar
126+
isntance.
127+
120128
* In :class:`~matplotlib.patches.FancyArrow`, the default arrow head width,
121129
``head_width``, has been made larger to produce a visible arrow head. The new
122130
value of this kwarg is ``head_width = 20 * width``.

lib/matplotlib/cm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ def __init__(self, norm=None, cmap=None):
193193
self.norm = norm
194194
#: The Colormap instance of this ScalarMappable.
195195
self.cmap = get_cmap(cmap)
196+
#: The last colorbar associated with this ScalarMappable. May be None.
196197
self.colorbar = None
197198
self.update_dict = {'array': False}
198199

200+
@cbook.deprecated('1.3', alternative='the colorbar attribute')
199201
def set_colorbar(self, im, ax):
200-
'set the colorbar image and axes associated with mappable'
201-
self.colorbar = im, ax
202+
"""set the colorbar and axes instances associated with mappable"""
203+
self.colorbar = im
202204

203205
def to_rgba(self, x, alpha=None, bytes=False):
204206
"""

lib/matplotlib/colorbar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def __init__(self, ax, cmap=None,
269269
extendrect=False,
270270
label='',
271271
):
272+
#: The axes that this colorbar lives in.
272273
self.ax = ax
273274
self._patch_ax()
274275
if cmap is None:
@@ -1270,6 +1271,6 @@ def colorbar_factory(cax, mappable, **kwargs):
12701271
cb = Colorbar(cax, mappable, **kwargs)
12711272

12721273
mappable.callbacksSM.connect('changed', cb.on_mappable_changed)
1273-
mappable.set_colorbar(cb, cax)
1274+
mappable.colorbar = cb
12741275

12751276
return cb

lib/mpl_toolkits/axes_grid/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,6 @@ def on_changed(m):
824824
cb.update_bruteforce(m)
825825

826826
cbid = mappable.callbacksSM.connect('changed', on_changed)
827-
mappable.set_colorbar(cb, cax)
827+
mappable.colorbar = cb
828828
ax.figure.sca(ax)
829829
return cb

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def on_changed(m):
9292
cb.update_bruteforce(m)
9393

9494
self.cbid = mappable.callbacksSM.connect('changed', on_changed)
95-
mappable.set_colorbar(cb, self)
95+
mappable.colorbar = cb
9696

9797
self.locator = cb.cbar_axis.get_major_locator()
9898

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,6 @@ def on_changed(m):
825825
cb.update_bruteforce(m)
826826

827827
cbid = mappable.callbacksSM.connect('changed', on_changed)
828-
mappable.set_colorbar(cb, cax)
828+
mappable.colorbar = cb
829829
ax.figure.sca(ax)
830830
return cb

0 commit comments

Comments
 (0)