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 146ba53

Browse filesBrowse files
committed
compressed layout moves suptitle
1 parent 86f04cb commit 146ba53
Copy full SHA for 146ba53

File tree

Expand file treeCollapse file tree

3 files changed

+38
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+38
-0
lines changed
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``suptitle`` in compressed layout
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Compressed layout now automatically positions the `~.Figure.suptitle` just
5+
above the top row of axes. To keep this title in its previous position,
6+
either pass ``in_layout=False`` or explicitly set ``y=0.98`` in the
7+
`~.Figure.suptitle` call.

‎lib/matplotlib/_constrained_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_constrained_layout.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ def do_constrained_layout(fig, h_pad, w_pad,
140140
w_pad=w_pad, hspace=hspace, wspace=wspace)
141141
else:
142142
_api.warn_external(warn_collapsed)
143+
144+
if ((suptitle := fig._suptitle) is not None and
145+
suptitle.get_in_layout() and suptitle._autopos):
146+
x, _ = suptitle.get_position()
147+
suptitle.set_position(
148+
(x, layoutgrids[fig].get_inner_bbox().y1 + h_pad))
149+
suptitle.set_verticalalignment('bottom')
143150
else:
144151
_api.warn_external(warn_collapsed)
145152
reset_margins(layoutgrids, fig)

‎lib/matplotlib/tests/test_constrainedlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_constrainedlayout.py
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,30 @@ def test_compressed1():
662662
np.testing.assert_allclose(pos.y0, 0.1934, atol=1e-3)
663663

664664

665+
def test_compressed_suptitle():
666+
fig, (ax0, ax1) = plt.subplots(
667+
nrows=2, figsize=(4, 10), layout="compressed",
668+
gridspec_kw={"height_ratios": (1 / 4, 3 / 4), "hspace": 0})
669+
670+
ax0.axis("equal")
671+
ax0.set_box_aspect(1/3)
672+
673+
ax1.axis("equal")
674+
ax1.set_box_aspect(1)
675+
676+
title = fig.suptitle("Title")
677+
fig.draw_without_rendering()
678+
assert title.get_position()[1] == pytest.approx(0.7457, abs=1e-3)
679+
680+
title = fig.suptitle("Title", y=0.98)
681+
fig.draw_without_rendering()
682+
assert title.get_position()[1] == 0.98
683+
684+
title = fig.suptitle("Title", in_layout=False)
685+
fig.draw_without_rendering()
686+
assert title.get_position()[1] == 0.98
687+
688+
665689
@pytest.mark.parametrize('arg, state', [
666690
(True, True),
667691
(False, False),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.