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

Skip to content

Commit 7796c24

Browse files
committed
FIX: fix taking suptitle (and friends) out of get_tightbbox
1 parent 12b7c29 commit 7796c24

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,24 @@ def _make_margin_suptitles(fig, renderer, *, w_pad=0, h_pad=0):
291291

292292
if fig._suptitle is not None and fig._suptitle.get_in_layout():
293293
p = fig._suptitle.get_position()
294-
fig._suptitle.set_position((p[0], 1 - h_pad_local))
295-
bbox = inv_trans_fig(fig._suptitle.get_tightbbox(renderer))
296-
fig._layoutgrid.edit_margin_min('top', bbox.height + 2.0 * h_pad)
294+
if p == (0.5, 0.98): # default position, so assume we can move
295+
fig._suptitle.set_position((p[0], 1 - h_pad_local))
296+
bbox = inv_trans_fig(fig._suptitle.get_tightbbox(renderer))
297+
fig._layoutgrid.edit_margin_min('top', bbox.height + 2 * h_pad)
297298

298299
if fig._supxlabel is not None and fig._supxlabel.get_in_layout():
299300
p = fig._supxlabel.get_position()
300-
fig._supxlabel.set_position((p[0], h_pad_local))
301-
bbox = inv_trans_fig(fig._supxlabel.get_tightbbox(renderer))
302-
fig._layoutgrid.edit_margin_min('bottom', bbox.height + 2.0 * h_pad)
301+
if p == (0.5, 0.01):
302+
fig._supxlabel.set_position((p[0], h_pad_local))
303+
bbox = inv_trans_fig(fig._supxlabel.get_tightbbox(renderer))
304+
fig._layoutgrid.edit_margin_min('bottom', bbox.height + 2 * h_pad)
303305

304306
if fig._supylabel is not None and fig._supxlabel.get_in_layout():
305307
p = fig._supylabel.get_position()
306-
fig._supylabel.set_position((w_pad_local, p[1]))
307-
bbox = inv_trans_fig(fig._supylabel.get_tightbbox(renderer))
308-
fig._layoutgrid.edit_margin_min('left', bbox.width + 2.0 * w_pad)
308+
if p == (0.02, 0.5,):
309+
fig._supylabel.set_position((w_pad_local, p[1]))
310+
bbox = inv_trans_fig(fig._supylabel.get_tightbbox(renderer))
311+
fig._layoutgrid.edit_margin_min('left', bbox.width + 2 * w_pad)
309312

310313

311314
def _match_submerged_margins(fig):

lib/matplotlib/figure.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ def _suplabels(self, t, info, **kwargs):
396396
sup.remove()
397397
else:
398398
suplab = sup
399-
if manual_position:
400-
suplab.set_in_layout(False)
401399
setattr(self, info['name'], suplab)
402400
self.stale = True
403401
return suplab

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def y_formatter(y, pos):
6161
plt.xlabel('X axis')
6262

6363

64+
@image_comparison(['bbox_inches_tight_suptile_non_default.png'],
65+
remove_text=False, savefig_kwarg={'bbox_inches': 'tight'},
66+
tol=0.1) # large tolerance because only testing clipping.
67+
def test_bbox_inches_tight_suptitle_non_default():
68+
fig, ax = plt.subplots()
69+
fig.suptitle('Booo', x=0.5, y=1.1)
70+
71+
6472
@image_comparison(['bbox_inches_tight_clipping'],
6573
remove_text=True, savefig_kwarg={'bbox_inches': 'tight'})
6674
def test_bbox_inches_tight_clipping():

0 commit comments

Comments
 (0)