8000 FIXes: make sure we don't call if not in layout · matplotlib/matplotlib@9755d8a · GitHub
[go: up one dir, main page]

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 9755d8a

Browse files
committed
FIXes: make sure we don't call if not in layout
1 parent 0a5959a commit 9755d8a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,22 @@ 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-
do_sup = (fig._suptitle is not None and
179-
fig._suptitle._layoutbox is not None)
180-
if do_sup:
181-
sup = fig._suptitle
182-
bbox = invTransFig(sup.get_window_extent(renderer=renderer))
178+
suptitle = fig._suptitle
179+
print(suptitle)
180+
do_suptitle = (suptitle is None or
181+
suptitle._layoutbox is None or
182+
not suptitle.get_in_layout())
183+
do_suptitle = not do_suptitle
184+
if do_suptitle:
185+
suptitle = fig._suptitle
186+
bbox = invTransFig(
187+
suptitle.get_window_extent(renderer=renderer))
183188
height = bbox.y1 - bbox.y0
184189
if np.isfinite(height):
185-
sup._layoutbox.edit_height(height + h_pad * 2)
190+
# reserve at top of figure include an h_pad above and below
191+
suptitle._layoutbox.edit_height(height + h_pad * 2)
192+
else:
193+
do_suptitle = False
186194

187195
# OK, the above lines up ax._poslayoutbox with ax._layoutbox
188196
# now we need to
@@ -223,9 +231,12 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
223231
# this axis, allowing users to hard-code the position,
224232
# so this does the same w/o zeroing layout.
225233
ax._set_position(newpos, which='original')
226-
if do_sup:
227-
newpos = sup._layoutbox.get_rect()
228-
sup.set_y(newpos[1] + newpos[3] - h_pad)
234+
if do_suptitle:
235+
newpos = suptitle._layoutbox.get_rect()
236+
suptitle.set_y(1.0 - h_pad)
237+
else:
238+
if suptitle is not None and suptitle._layoutbox is not None:
239+
suptitle._layoutbox.edit_height(0)
229240

230241
else:
231242
cbook._warn_external('constrained_layout not applied. At least '

0 commit comments

Comments
 (0)
0