From b76aeaad3e819f1f5e5fe31ca2d89a07346f18be Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 24 Feb 2018 17:23:57 -0800 Subject: [PATCH 1/2] FIX: colorbar check for constrained layout --- lib/matplotlib/colorbar.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 380f4493bbb3..4a693bb0fbe5 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -1132,8 +1132,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15, parents = np.atleast_1d(parents).ravel() # check if using constrained_layout: - gs = parents[0].get_subplotspec().get_gridspec() - using_constrained_layout = (gs._layoutbox is not None) + try: + gs = parents[0].get_subplotspec().get_gridspec() + using_constrained_layout = (gs._layoutbox is not None) + except AttributeError: + using_constrained_layout = False + # defaults are not appropriate for constrained_layout: pad0 = loc_settings['pad'] if using_constrained_layout: From e5f073c068371680bdac360ddb25aaee85fb491e Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 24 Feb 2018 19:42:58 -0800 Subject: [PATCH 2/2] TST: colorbar check for constrained layout --- lib/matplotlib/tests/test_constrainedlayout.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/tests/test_constrainedlayout.py b/lib/matplotlib/tests/test_constrainedlayout.py index ab720618fc97..9c36fb2476ee 100644 --- a/lib/matplotlib/tests/test_constrainedlayout.py +++ b/lib/matplotlib/tests/test_constrainedlayout.py @@ -377,3 +377,14 @@ def test_constrained_layout19(): ax.set_title('') fig.canvas.draw() assert all(ax.get_position().extents == ax2.get_position().extents) + + +def test_constrained_layout20(): + 'Smoke test cl does not mess up added axes' + gx = np.linspace(-5, 5, 4) + img = np.hypot(gx, gx[:, None]) + + fig = plt.figure() + ax = fig.add_axes([0, 0, 1, 1]) + mesh = ax.pcolormesh(gx, gx, img) + fig.colorbar(mesh)