Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdc92c7

Browse files
authored
Merge pull request #14234 from meeseeksmachine/auto-backport-of-pr-14185-on-v3.1.x
Backport PR #14185 on branch v3.1.x (FIX: adjust suptitle placement after calling constrained_layout)
2 parents 1a525a7 + d665d03 commit fdc92c7

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)