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