Skip to content

Commit 5435e6f

Browse files
authored
Merge pull request #20763 from meeseeksmachine/auto-backport-of-pr-20761-on-v3.4.x
Backport PR #20761 on branch v3.4.x (Fix suplabel autopos)
2 parents 30b9e16 + 5b64248 commit 5435e6f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ def _suplabels(self, t, info, **kwargs):
373373

374374
x = kwargs.pop('x', None)
375375
y = kwargs.pop('y', None)
376-
autopos = x is None and y is None
376+
if info['name'] in ['_supxlabel', '_suptitle']:
377+
autopos = y is None
378+
elif info['name'] == '_supylabel':
379+
autopos = x is None
377380
if x is None:
378381
x = info['x0']
379382
if y is None:

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,26 @@ def test_align_labels():
555555
after_align[1].x0, rtol=0, atol=1e-05)
556556
# ensure labels do not go off the edge
557557
assert after_align[0].x0 >= 1
558+
559+
560+
def test_suplabels():
561+
fig, ax = plt.subplots(constrained_layout=True)
562+
fig.canvas.draw()
563+
pos0 = ax.get_tightbbox(fig.canvas.get_renderer())
564+
fig.supxlabel('Boo')
565+
fig.supylabel('Booy')
566+
fig.canvas.draw()
567+
pos = ax.get_tightbbox(fig.canvas.get_renderer())
568+
assert pos.y0 > pos0.y0 + 10.0
569+
assert pos.x0 > pos0.x0 + 10.0
570+
571+
fig, ax = plt.subplots(constrained_layout=True)
572+
fig.canvas.draw()
573+
pos0 = ax.get_tightbbox(fig.canvas.get_renderer())
574+
# check that specifying x (y) doesn't ruin the layout
575+
fig.supxlabel('Boo', x=0.5)
576+
fig.supylabel('Boo', y=0.5)
577+
fig.canvas.draw()
578+
pos = ax.get_tightbbox(fig.canvas.get_renderer())
579+
assert pos.y0 > pos0.y0 + 10.0
580+
assert pos.x0 > pos0.x0 + 10.0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy