@@ -176,12 +176,17 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
176
176
_make_layout_margins (ax , renderer , h_pad , w_pad )
177
177
178
178
# 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 ))
182
186
height = bbox .y1 - bbox .y0
183
187
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 )
185
190
186
191
# OK, the above lines up ax._poslayoutbox with ax._layoutbox
187
192
# now we need to
@@ -222,6 +227,12 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
222
227
# this axis, allowing users to hard-code the position,
223
228
# so this does the same w/o zeroing layout.
224
229
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 )
225
236
else :
226
237
cbook ._warn_external ('constrained_layout not applied. At least '
227
238
'one axes collapsed to zero width or height.' )
0 commit comments