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

Skip to content

Commit e3a5214

Browse files
committed
Warn in colorbar() when mappable.axes != figure.gca().
1 parent 8e7c7ab commit e3a5214

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Figure.colorbar now warns when the mappable's axes is different from the current axes
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Currently, `.Figure.colorbar` steals space by default from the current axes
5+
to place the colorbar. In a future version, it will steal space from the
6+
mappable's axes instead. In preparation for this change, `.Figure.colorbar`
7+
now emits a warning when the current axes is not the same as the mappable's
8+
axes.

lib/matplotlib/blocking_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class BlockingContourLabeler(BlockingMouseInput):
277277

278278
def __init__(self, cs):
279279
self.cs = cs
280-
BlockingMouseInput.__init__(self, fig=cs.ax.figure)
280+
BlockingMouseInput.__init__(self, fig=cs.axes.figure)
281281

282282
def add_click(self, event):
283283
self.button1(event)

lib/matplotlib/figure.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,13 +2318,20 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
23182318
"""%(colorbar_doc)s"""
23192319
if ax is None:
23202320
ax = self.gca()
2321+
if hasattr(mappable, "axes") and ax is not mappable.axes:
2322+
cbook.warn_deprecated(
2323+
"3.4", message="Starting from Matplotlib 3.6, colorbar() "
2324+
"will steal space from the mappable's axes, rather than "
2325+
"from the current axes, to place the colorbar. To "
2326+
"silence this warning, explicitly pass the 'ax' argument "
2327+
"to colorbar().")
23212328

23222329
# Store the value of gca so that we can set it back later on.
23232330
current_ax = self.gca()
23242331

23252332
if cax is None:
2326-
if use_gridspec and isinstance(ax, SubplotBase) \
2327-
and (not self.get_constrained_layout()):
2333+
if (use_gridspec and isinstance(ax, SubplotBase)
2334+
and not self.get_constrained_layout()):
23282335
cax, kw = cbar.make_axes_gridspec(ax, **kw)
23292336
else:
23302337
cax, kw = cbar.make_axes(ax, **kw)

0 commit comments

Comments
 (0)