diff --git a/lib/matplotlib/_constrained_layout.py b/lib/matplotlib/_constrained_layout.py index 39795b544a3c..a2a70fdc0212 100644 --- a/lib/matplotlib/_constrained_layout.py +++ b/lib/matplotlib/_constrained_layout.py @@ -176,12 +176,17 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad, _make_layout_margins(ax, renderer, h_pad, w_pad) # do layout for suptitle. - if fig._suptitle is not None and fig._suptitle._layoutbox is not None: - sup = fig._suptitle - bbox = invTransFig(sup.get_window_extent(renderer=renderer)) + suptitle = fig._suptitle + do_suptitle = (suptitle is not None and + suptitle._layoutbox is not None and + suptitle.get_in_layout()) + if do_suptitle: + bbox = invTransFig( + suptitle.get_window_extent(renderer=renderer)) height = bbox.y1 - bbox.y0 if np.isfinite(height): - sup._layoutbox.edit_height(height+h_pad) + # reserve at top of figure include an h_pad above and below + suptitle._layoutbox.edit_height(height + h_pad * 2) # OK, the above lines up ax._poslayoutbox with ax._layoutbox # now we need to @@ -222,6 +227,12 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad, # this axis, allowing users to hard-code the position, # so this does the same w/o zeroing layout. ax._set_position(newpos, which='original') + if do_suptitle: + newpos = suptitle._layoutbox.get_rect() + suptitle.set_y(1.0 - h_pad) + else: + if suptitle is not None and suptitle._layoutbox is not None: + suptitle._layoutbox.edit_height(0) else: cbook._warn_external('constrained_layout not applied. At least ' 'one axes collapsed to zero width or height.') diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png index b0cc59893d15..c262adc048fb 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png index c5361afd402e..4cc1ee216fd2 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png differ
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: