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