Skip to content

Commit 96cae15

Browse files
anntzertacaswell
authored andcommitted
Warn in colorbar() when mappable.axes != figure.gca().
1 parent 3bbc78a commit 96cae15

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Deprecations
22
------------
33

4+
Figure.colorbar now warns when the mappable's axes is different from the current axes
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
Currently, `.Figure.colorbar` steals space by default from the current axes
8+
to place the colorbar. In a future version, it will steal space from the
9+
mappable's axes instead. In preparation for this change, `.Figure.colorbar`
10+
now emits a warning when the current axes is not the same as the mappable's
11+
axes.
12+
13+
The ``.ax`` attribute to `.ContourSet` is deprecated in favor of
14+
``.axes`` for consistency with artists (even though `.ContourSet` is not an
15+
`.Artist` subclass).
16+
17+
418
``dpi_cor`` property of `.FancyArrowPatch`
519
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
620
This parameter is considered internal and deprecated.

lib/matplotlib/blocking_input.py

+1-1
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

+9-2
Original file line numberDiff line numberDiff line change
@@ -2323,13 +2323,20 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
23232323
"""
23242324
if ax is None:
23252325
ax = self.gca()
2326+
if hasattr(mappable, "axes") and ax is not mappable.axes:
2327+
cbook.warn_deprecated(
2328+
"3.4", message="Starting from Matplotlib 3.6, colorbar() "
2329+
"will steal space from the mappable's axes, rather than "
2330+
"from the current axes, to place the colorbar. To "
2331+
"silence this warning, explicitly pass the 'ax' argument "
2332+
"to colorbar().")
23262333

23272334
# Store the value of gca so that we can set it back later on.
23282335
current_ax = self.gca()
23292336

23302337
if cax is None:
2331-
if use_gridspec and isinstance(ax, SubplotBase) \
2332-
and (not self.get_constrained_layout()):
2338+
if (use_gridspec and isinstance(ax, SubplotBase)
2339+
and not self.get_constrained_layout()):
23332340
cax, kw = cbar.make_axes_gridspec(ax, **kw)
23342341
else:
23352342
cax, kw = cbar.make_axes(ax, **kw)

0 commit comments

Comments
 (0)