@@ -175,12 +175,17 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
175175 _make_layout_margins (ax , renderer , h_pad , w_pad )
176176
177177 # do layout for suptitle.
178- if fig ._suptitle is not None and fig ._suptitle ._layoutbox is not None :
179- sup = fig ._suptitle
180- bbox = invTransFig (sup .get_window_extent (renderer = renderer ))
178+ suptitle = fig ._suptitle
179+ do_suptitle = (suptitle is not None and
180+ suptitle ._layoutbox is not None and
181+ suptitle .get_in_layout ())
182+ if do_suptitle :
183+ bbox = invTransFig (
184+ suptitle .get_window_extent (renderer = renderer ))
181185 height = bbox .y1 - bbox .y0
182186 if np .isfinite (height ):
183- sup ._layoutbox .edit_height (height + h_pad )
187+ # reserve at top of figure include an h_pad above and below
188+ suptitle ._layoutbox .edit_height (height + h_pad * 2 )
184189
185190 # OK, the above lines up ax._poslayoutbox with ax._layoutbox
186191 # now we need to
@@ -221,6 +226,12 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
221226 # this axis, allowing users to hard-code the position,
222227 # so this does the same w/o zeroing layout.
223228 ax ._set_position (newpos , which = 'original' )
229+ if do_suptitle :
230+ newpos = suptitle ._layoutbox .get_rect ()
231+ suptitle .set_y (1.0 - h_pad )
232+ else :
233+ if suptitle is not None and suptitle ._layoutbox is not None :
234+ suptitle ._layoutbox .edit_height (0 )
224235 else :
225236 cbook ._warn_external ('constrained_layout not applied. At least '
226237 'one axes collapsed to zero width or height.' )
0 commit comments