Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d665d03

Browse filesBrowse files
dstansbyMeeseeksDev[bot]
authored andcommitted
Backport PR #14185: FIX: adjust suptitle placement after calling constrained_layout
1 parent 1a525a7 commit d665d03
Copy full SHA for d665d03

File tree

Expand file treeCollapse file tree

3 files changed

+15
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-4
lines changed

‎lib/matplotlib/_constrained_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_constrained_layout.py
+15-4Lines 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.')
Loading
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.