Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Fix contrained layout applying pad multiple times#30108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
rcomer wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromrcomer:submerged-margins
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletionslib/matplotlib/_constrained_layout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -538,14 +538,10 @@ def match_submerged_margins(layoutgrids, fig):

# interior columns:
if len(ss1.colspan) > 1:
maxsubl = np.max(
lg1.margin_vals['left'][ss1.colspan[1:]] +
lg1.margin_vals['leftcb'][ss1.colspan[1:]]
)
maxsubr = np.max(
lg1.margin_vals['right'][ss1.colspan[:-1]] +
lg1.margin_vals['rightcb'][ss1.colspan[:-1]]
)
leftcb = lg1.margin_vals['leftcb'][ss1.colspan[1:]]
rightcb = lg1.margin_vals['rightcb'][ss1.colspan[:-1]]
maxsubl = np.max(lg1.margin_vals['left'][ss1.colspan[1:]] + leftcb)
maxsubr = np.max(lg1.margin_vals['right'][ss1.colspan[:-1]] + rightcb)
for ax2 in axs:
ss2 = ax2.get_subplotspec()
lg2 = layoutgrids[ss2.get_gridspec()]
Expand All@@ -560,22 +556,17 @@ def match_submerged_margins(layoutgrids, fig):
lg2.margin_vals['rightcb'][ss2.colspan[:-1]])
if maxsubr2 > maxsubr:
maxsubr = maxsubr2
for iin ss1.colspan[1:]:
lg1.edit_margin_min('left', maxsubl, cell=i)
for iin ss1.colspan[:-1]:
lg1.edit_margin_min('right', maxsubr, cell=i)
for i, cbinzip(ss1.colspan[1:], leftcb):
lg1.edit_margin_min('left', maxsubl - cb, cell=i)
for i, cbinzip(ss1.colspan[:-1], rightcb):
lg1.edit_margin_min('right', maxsubr - cb, cell=i)

# interior rows:
if len(ss1.rowspan) > 1:
maxsubt = np.max(
lg1.margin_vals['top'][ss1.rowspan[1:]] +
lg1.margin_vals['topcb'][ss1.rowspan[1:]]
)
maxsubb = np.max(
lg1.margin_vals['bottom'][ss1.rowspan[:-1]] +
lg1.margin_vals['bottomcb'][ss1.rowspan[:-1]]
)

topcb = lg1.margin_vals['topcb'][ss1.rowspan[1:]]
bottomcb = lg1.margin_vals['bottomcb'][ss1.rowspan[:-1]]
maxsubt = np.max(lg1.margin_vals['top'][ss1.rowspan[1:]] + topcb)
maxsubb = np.max(lg1.margin_vals['bottom'][ss1.rowspan[:-1]] + bottomcb)
for ax2 in axs:
ss2 = ax2.get_subplotspec()
lg2 = layoutgrids[ss2.get_gridspec()]
Expand All@@ -589,10 +580,10 @@ def match_submerged_margins(layoutgrids, fig):
lg2.margin_vals['bottom'][ss2.rowspan[:-1]] +
lg2.margin_vals['bottomcb'][ss2.rowspan[:-1]]
), maxsubb])
for iin ss1.rowspan[1:]:
lg1.edit_margin_min('top', maxsubt, cell=i)
for iin ss1.rowspan[:-1]:
lg1.edit_margin_min('bottom', maxsubb, cell=i)
for i, cbinzip(ss1.rowspan[1:], topcb):
lg1.edit_margin_min('top', maxsubt - cb, cell=i)
for i, cbinzip(ss1.rowspan[:-1], bottomcb):
lg1.edit_margin_min('bottom', maxsubb - cb, cell=i)

return axs

Expand Down
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletionslib/matplotlib/tests/test_constrainedlayout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -741,3 +741,37 @@ def test_submerged_subfig():
for ax in axs[1:]:
assert np.allclose(ax.get_position().bounds[-1],
axs[0].get_position().bounds[-1], atol=1e-6)


def test_submerged_height_gap():
"""Test that the gap between rows does not depend on the number of columns."""

mosaic1 = "AC;BC"
mosaic2 = "ACDE;BCDE"

fig1, ax_dir1 = plt.subplot_mosaic(mosaic1, layout='constrained')
fig2, ax_dir2 = plt.subplot_mosaic(mosaic2, layout='constrained')
for fig in fig1, fig2:
fig.get_layout_engine().set(h_pad=0.2)
fig.draw_without_rendering()

for label in 'A', 'B':
np.testing.assert_allclose(ax_dir1[label].get_position().bounds[-1],
ax_dir2[label].get_position().bounds[-1])


def test_submerged_width_gap():
"""Test that the gap between columns does not depend on the number of rows."""

mosaic1 = "AB;CC"
mosaic2 = "AB;CC;DD"

fig1, ax_dir1 = plt.subplot_mosaic(mosaic1, layout='constrained')
fig2, ax_dir2 = plt.subplot_mosaic(mosaic2, layout='constrained')
for fig in fig1, fig2:
fig.get_layout_engine().set(w_pad=0.2)
fig.draw_without_rendering()

for label in 'A', 'B':
np.testing.assert_allclose(ax_dir1[label].get_position().bounds[-2],
ax_dir2[label].get_position().bounds[-2])
Loading

[8]ページ先頭

©2009-2025 Movatter.jp