8000 Warn in colorbar() when mappable.axes != figure.gca(). · matplotlib/matplotlib@c40c780 · GitHub
[go: up one dir, main page]

Skip to content

Commit c40c780

Browse files
committed
Warn in colorbar() when mappable.axes != figure.gca().
1 parent 9cffe0e commit c40c780

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
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/figure.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,13 +2127,20 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
21272127
"""
21282128
if ax is None:
21292129
ax = self.gca()
2130+
if ax is not mappable.axes:
2131+
cbook.warn_deprecated(
2132+
"3.1", message="Starting from Matplotlib 3.3, colorbar() "
2133+
"will steal space from the mappable's axes, rather than "
2134+
"from the current axes, to place the colorbar. To "
2135+
"silence this warning, explicitly pass the 'ax' argument "
2136+
"to colorbar().")
21302137

21312138
# Store the value of gca so that we can set it back later on.
21322139
current_ax = self.gca()
21332140

21342141
if cax is None:
2135-
if use_gridspec and isinstance(ax, SubplotBase) \
2136-
and (not self.get_constrained_layout()):
2142+
if (use_gridspec and isinstance(ax, SubplotBase)
2143+
and not self.get_constrained_layout()):
21372144
cax, kw = cbar.make_axes_gridspec(ax, **kw)
21382145
else:
21392146
cax, kw = cbar.make_axes(ax, **kw)

0 commit comments

Comments
 (0)
0