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 4f7b8b0

Browse filesBrowse files
committed
FIX: adjust suptitle placement after calling CL
1 parent 9b49c3c commit 4f7b8b0
Copy full SHA for 4f7b8b0

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
@@ -175,12 +175,17 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
175175
_make_layout_margins(ax, renderer, h_pad, w_pad)
176176

177177
# 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))
181185
height = bbox.y1 - bbox.y0
182186
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)
184189

185190
# OK, the above lines up ax._poslayoutbox with ax._layoutbox
186191
# now we need to
@@ -221,6 +226,12 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
221226
# this axis, allowing users to hard-code the position,
222227
# so this does the same w/o zeroing layout.
223228
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)
224235
else:
225236
cbook._warn_external('constrained_layout not applied. At least '
226237
'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.