Skip to content

Commit 9339196

Browse files
efiringMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #10594: FIX: colorbar check for constrained layout
1 parent c0294a1 commit 9339196

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/matplotlib/colorbar.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
11321132
parents = np.atleast_1d(parents).ravel()
11331133

11341134
# check if using constrained_layout:
1135-
gs = parents[0].get_subplotspec().get_gridspec()
1136-
using_constrained_layout = (gs._layoutbox is not None)
1135+
try:
1136+
gs = parents[0].get_subplotspec().get_gridspec()
1137+
using_constrained_layout = (gs._layoutbox is not None)
1138+
except AttributeError:
1139+
using_constrained_layout = False
1140+
11371141
# defaults are not appropriate for constrained_layout:
11381142
pad0 = loc_settings['pad']
11391143
if using_constrained_layout:

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,14 @@ def test_constrained_layout19():
377377
ax.set_title('')
378378
fig.canvas.draw()
379379
assert all(ax.get_position().extents == ax2.get_position().extents)
380+
381+
382+
def test_constrained_layout20():
383+
'Smoke test cl does not mess up added axes'
384+
gx = np.linspace(-5, 5, 4)
385+
img = np.hypot(gx, gx[:, None])
386+
387+
fig = plt.figure()
388+
ax = fig.add_axes([0, 0, 1, 1])
389+
mesh = ax.pcolormesh(gx, gx, img)
390+
fig.colorbar(mesh)

0 commit comments

Comments
 (0)