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 901cfa6

Browse filesBrowse files
authored
Merge branch 'matplotlib:main' into main
2 parents 87e8e37 + 74ae218 commit 901cfa6
Copy full SHA for 901cfa6

File tree

2 files changed

+26
-2
lines changed
Filter options

2 files changed

+26
-2
lines changed

‎lib/matplotlib/_constrained_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_constrained_layout.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,13 @@ def match_submerged_margins(layoutgrids, fig):
521521
See test_constrained_layout::test_constrained_layout12 for an example.
522522
"""
523523

524+
axsdone = []
524525
for sfig in fig.subfigs:
525-
match_submerged_margins(layoutgrids, sfig)
526+
axsdone += match_submerged_margins(layoutgrids, sfig)
526527

527528
axs = [a for a in fig.get_axes()
528-
if a.get_subplotspec() is not None and a.get_in_layout()]
529+
if (a.get_subplotspec() is not None and a.get_in_layout() and
530+
a not in axsdone)]
529531

530532
for ax1 in axs:
531533
ss1 = ax1.get_subplotspec()
@@ -592,6 +594,8 @@ def match_submerged_margins(layoutgrids, fig):
592594
for i in ss1.rowspan[:-1]:
593595
lg1.edit_margin_min('bottom', maxsubb, cell=i)
594596

597+
return axs
598+
595599

596600
def get_cb_parent_spans(cbax):
597601
"""

‎lib/matplotlib/tests/test_constrainedlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_constrainedlayout.py
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,23 @@ def test_layout_leak():
721721
gc.collect()
722722
assert not any(isinstance(obj, mpl._layoutgrid.LayoutGrid)
723723
for obj in gc.get_objects())
724+
725+
726+
def test_submerged_subfig():
727+
"""
728+
Test that the submerged margin logic does not get called multiple times
729+
on same axes if it is already in a subfigure
730+
"""
731+
fig = plt.figure(figsize=(4, 5), layout='constrained')
732+
figures = fig.subfigures(3, 1)
733+
axs = []
734+
for f in figures.flatten():
735+
gs = f.add_gridspec(2, 2)
736+
for i in range(2):
737+
axs += [f.add_subplot(gs[i, 0])]
738+
axs[-1].plot()
739+
f.add_subplot(gs[:, 1]).plot()
740+
fig.draw_without_rendering()
741+
for ax in axs[1:]:
742+
assert np.allclose(ax.get_position().bounds[-1],
743+
axs[0].get_position().bounds[-1], atol=1e-6)

0 commit comments

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