Skip to content

Commit e1610c2

Browse files
authored
Merge pull request #22619 from meeseeksmachine/auto-backport-of-pr-22611-on-v3.5.x
Backport PR #22611 on branch v3.5.x (FIX: Colorbars check for subplotspec attribute before using)
2 parents f09af98 + 4f70871 commit e1610c2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,10 @@ def get_subplotspec(self):
280280
# make tight_layout happy..
281281
ss = getattr(self._cbar.ax, 'get_subplotspec', None)
282282
if ss is None:
283-
if self._orig_locator is None:
283+
if not hasattr(self._orig_locator, "get_subplotspec"):
284284
return None
285-
ss = self._orig_locator.get_subplotspec()
286-
else:
287-
ss = ss()
288-
return ss
285+
ss = self._orig_locator.get_subplotspec
286+
return ss()
289287

290288

291289
class Colorbar:

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def test_axesgrid_colorbar_log_smoketest():
9999
grid.cbar_axes[0].colorbar(im)
100100

101101

102+
def test_inset_colorbar_tight_layout_smoketest():
103+
fig, ax = plt.subplots(1, 1)
104+
pts = ax.scatter([0, 1], [0, 1], c=[1, 5])
105+
106+
cax = inset_axes(ax, width="3%", height="70%")
107+
plt.colorbar(pts, cax=cax)
108+
109+
with pytest.warns(UserWarning, match="This figure includes Axes"):
110+
# Will warn, but not raise an error
111+
plt.tight_layout()
112+
113+
102114
@image_comparison(['inset_locator.png'], style='default', remove_text=True)
103115
def test_inset_locator():
104116
fig, ax = plt.subplots(figsize=[5, 4])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy