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

Skip to content

Commit ebe0688

Browse files
committed
FIX
1 parent cf25a70 commit ebe0688

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,31 +277,34 @@ def _make_layout_margins(fig, renderer, *, w_pad=0, h_pad=0,
277277
def _make_margin_suptitles(fig, renderer, *, w_pad=0, h_pad=0):
278278
# Figure out how large the suptitle is and make the
279279
# top level figure margin larger.
280-
280+
281281
invTransFig = fig.transFigure.inverted().transform_bbox
282-
padboxF = mtransforms.Bbox([[0, 0], [w_pad, h_pad]])
283-
padboxLocal = (fig.transFigure - fig.transSubfigure).transform_bbox(padboxF)
284-
h_padLocal = padboxLocal.height
285-
w_padLocal = padboxLocal.width
282+
# get the h_pad and w_pad as distances in the local subfigure coordinates:
283+
padbox = mtransforms.Bbox([[0, 0], [w_pad, h_pad]])
284+
padbox = (fig.transFigure -
285+
fig.transSubfigure).transform_bbox(padbox)
286+
h_pad_local = padbox.height
287+
w_pad_local = padbox.width
286288

287289
for panel in fig.subfigs:
288290
_make_margin_suptitles(panel, renderer, w_pad=w_pad, h_pad=h_pad)
289291

290292
if fig._suptitle is not None and fig._suptitle.get_in_layout():
291293
p = fig._suptitle.get_position()
292-
fig._suptitle.set_position((p[0], 1 - h_padLocal))
293-
bbox = invTransFig(fig._suptitle.get_tightbbox(renderer)) # fig coords
294+
fig._suptitle.set_position((p[0], 1 - h_pad_local))
295+
bbox = invTransFig(fig._suptitle.get_tightbbox(renderer)) # fig coords
294296
fig._layoutgrid.edit_margin_min('top', bbox.height + 2.0 * h_pad)
295297

296298
if fig._supxlabel is not None and fig._supxlabel.get_in_layout():
297299
p = fig._supxlabel.get_position()
298-
fig._supxlabel.set_position((p[0], h_padLocal))
300+
fig._supxlabel.set_position((p[0], h_pad_local))
301+
bbox = invTransFig(fig._supxlabel.get_tightbbox(renderer)) # fig coord
299302
fig._layoutgrid.edit_margin_min('bottom', bbox.height + 2 * h_pad)
300303

301304
if fig._supylabel is not None and fig._supxlabel.get_in_layout():
302305
p = fig._supylabel.get_position()
303-
fig._supylabel.set_position((w_padLocal, p[1]))
304-
bbox = invTransFig(fig._supylabel.get_tightbbox(renderer)) # fig coords
306+
fig._supylabel.set_position((w_pad_local, p[1]))
307+
bbox = invTransFig(fig._supylabel.get_tightbbox(renderer)) # fig coord
305308
fig._layoutgrid.edit_margin_min('left', bbox.width + 2 * w_pad)
306309

307310

0 commit comments

Comments
 (0)