8000 Backport PR #14185 on branch v3.1.x (FIX: adjust suptitle placement after calling constrained_layout) by meeseeksmachine · Pull Request #14234 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #14185 on branch v3.1.x (FIX: adjust suptitle placement after calling constrained_layout) #14234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/matplotlib/_constrained_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
_make_layout_margins(ax, renderer, h_pad, w_pad)

# do layout for suptitle.
if fig._suptitle is not None and fig._suptitle._layoutbox is not None:
sup = fig._suptitle
bbox = invTransFig(sup.get_window_extent(renderer=renderer))
suptitle = fig._suptitle
do_suptitle = (suptitle is not None and
suptitle._layoutbox is not None and
suptitle.get_in_layout())
if do_suptitle:
bbox = invTransFig(
suptitle.get_window_extent(renderer=renderer))
height = bbox.y1 - bbox.y0
if np.isfinite(height):
sup._layoutbox.edit_height(height+h_pad)
# reserve at top of figure include an h_pad above and below
suptitle._layoutbox.edit_height(height + h_pad * 2)

# OK, the above lines up ax._poslayoutbox with ax._layoutbox
# now we need to
Expand Down Expand Up @@ -222,6 +227,12 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
# this axis, allowing users to hard-code the position,
# so this does the same w/o zeroing layout.
ax._set_position(newpos, which='original')
if do_suptitle:
newpos = suptitle._layoutbox.get_rect()
suptitle.set_y(1.0 - h_pad)
else:
if suptitle is not None and suptitle._layoutbox is not None:
suptitle._layoutbox.edit_height(0)
else:
cbook._warn_external('constrained_layout not applied. At least '
'one axes collapsed to zero width or height.')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0