Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecated the set_colorbar method on a scalar mappable. #2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Sorry - typo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. We can just push that fix directly to master.


* 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``.
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have missed some other PR... there weren't any old code that would have queried and expected a tuple from the colorbar attribute, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I don't think anything is making use of it (at least, there are no tests which exercise it, and a thorough grepping didn't throw anything up)


def to_rgba(self, x, alpha=None, bytes=False):
"""
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1269,6 +1270,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
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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