From b50237da013f4053d88ffe7bc04c2a855111b0d8 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Thu, 23 May 2013 15:56:35 +0100 Subject: [PATCH 1/2] Deprecated the set_colorbar method on a scalar mappable. --- lib/matplotlib/cm.py | 6 ++++-- lib/matplotlib/colorbar.py | 2 +- lib/mpl_toolkits/axes_grid/colorbar.py | 2 +- lib/mpl_toolkits/axes_grid1/axes_grid.py | 2 +- lib/mpl_toolkits/axes_grid1/colorbar.py | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 9432cb843a78..5eac87469d55 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -193,12 +193,14 @@ def __init__(self, norm=None, cmap=None): self.norm = norm #: The Colormap instance of this ScalarMappable. self.cmap = get_cmap(cmap) + #: The last colorbar associated with this ScalarMappable. May be None. self.colorbar = None self.update_dict = {'array': False} + @cbook.deprecated('1.3', alternative='the colorbar attribute') def set_colorbar(self, im, ax): - 'set the colorbar image and axes associated with mappable' - self.colorbar = im, ax + """set the colorbar and axes instances associated with mappable""" + self.colorbar = im def to_rgba(self, x, alpha=None, bytes=False): """ diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 5a6678036b44..da3d4d0760f7 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -1269,6 +1269,6 @@ def colorbar_factory(cax, mappable, **kwargs): cb = Colorbar(cax, mappable, **kwargs) mappable.callbacksSM.connect('changed', cb.on_mappable_changed) - mappable.set_colorbar(cb, cax) + mappable.colorbar = cb return cb diff --git a/lib/mpl_toolkits/axes_grid/colorbar.py b/lib/mpl_toolkits/axes_grid/colorbar.py index 203724abfd29..a70608c8474f 100644 --- a/lib/mpl_toolkits/axes_grid/colorbar.py +++ b/lib/mpl_toolkits/axes_grid/colorbar.py @@ -824,6 +824,6 @@ def on_changed(m): cb.update_bruteforce(m) cbid = mappable.callbacksSM.connect('changed', on_changed) - mappable.set_colorbar(cb, cax) + mappable.colorbar = cb ax.figure.sca(ax) return cb diff --git a/lib/mpl_toolkits/axes_grid1/axes_grid.py b/lib/mpl_toolkits/axes_grid1/axes_grid.py index 45bff69737fd..f8a4b70a5cb0 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_grid.py +++ b/lib/mpl_toolkits/axes_grid1/axes_grid.py @@ -92,7 +92,7 @@ def on_changed(m): cb.update_bruteforce(m) self.cbid = mappable.callbacksSM.connect('changed', on_changed) - mappable.set_colorbar(cb, self) + mappable.colorbar = cb self.locator = cb.cbar_axis.get_major_locator() diff --git a/lib/mpl_toolkits/axes_grid1/colorbar.py b/lib/mpl_toolkits/axes_grid1/colorbar.py index 59838319191b..8338b053d8b6 100644 --- a/lib/mpl_toolkits/axes_grid1/colorbar.py +++ b/lib/mpl_toolkits/axes_grid1/colorbar.py @@ -825,6 +825,6 @@ def on_changed(m): cb.update_bruteforce(m) cbid = mappable.callbacksSM.connect('changed', on_changed) - mappable.set_colorbar(cb, cax) + mappable.colorbar = cb ax.figure.sca(ax) return cb From 785d66ae15932af884d4dad13f236dc1f0e4f30e Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 24 May 2013 10:18:04 +0100 Subject: [PATCH 2/2] Added an api_changes note about the deprecation of ScalarMappable.set_colorbar --- doc/api/api_changes.rst | 8 ++++++++ lib/matplotlib/colorbar.py | 1 + 2 files changed, 9 insertions(+) diff --git a/doc/api/api_changes.rst b/doc/api/api_changes.rst index 8be7932f23d3..8100c0c71665 100644 --- a/doc/api/api_changes.rst +++ b/doc/api/api_changes.rst @@ -117,6 +117,14 @@ Changes in 1.3.x position type. Previously, it would draw the right or top spine at +1 data offset. +* The ScalarMappable class' set_colorbar is now deprecated. Instead, the + :attr:`matplotlib.cm.ScalarMappable.colorbar` attribute should be used. + In previous matplotlib versions this attribute was an undocumented tuple + of ``(colorbar_instance, colorbar_axes)`` but is now just + ``colorbar_instance``. To get the colorbar axes it is possible to just use + the :attr:`~matplotlib.colorbar.ColorbarBase.ax` attribute on a colorbar + isntance. + * In :class:`~matplotlib.patches.FancyArrow`, the default arrow head width, ``head_width``, has been made larger to produce a visible arrow head. The new value of this kwarg is ``head_width = 20 * width``. diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index da3d4d0760f7..319e87c22834 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -269,6 +269,7 @@ def __init__(self, ax, cmap=None, extendrect=False, label='', ): + #: The axes that this colorbar lives in. self.ax = ax self._patch_ax() if cmap is None: