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

Commitd77efae

Browse files
committed
FIX: fix submerged margins algorithm being applied twice
1 parent200808c commitd77efae

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

‎lib/matplotlib/_constrained_layout.py

Lines 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
forsfiginfig.subfigs:
525-
match_submerged_margins(layoutgrids,sfig)
526+
axsdone+=match_submerged_margins(layoutgrids,sfig)
526527

527528
axs= [aforainfig.get_axes()
528-
ifa.get_subplotspec()isnotNoneanda.get_in_layout()]
529+
if (a.get_subplotspec()isnotNoneanda.get_in_layout()and
530+
anotinaxsdone)]
529531

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

597+
returnaxs
598+
595599

596600
defget_cb_parent_spans(cbax):
597601
"""

‎lib/matplotlib/tests/test_constrainedlayout.py

Lines 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
assertnotany(isinstance(obj,mpl._layoutgrid.LayoutGrid)
723723
forobjingc.get_objects())
724+
725+
726+
deftest_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+
forfinfigures.flatten():
735+
gs=f.add_gridspec(2,2)
736+
foriinrange(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+
foraxinaxs[1:]:
742+
assertnp.allclose(ax.get_position().bounds[-1],
743+
axs[0].get_position().bounds[-1],atol=1e-6)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp