Skip to content

Commit b09aad2

Browse files
authored
Merge pull request #21481 from jklymak/fix-arb-gs-subfigure
FIX: spanning subfigures
2 parents d448de3 + 9793992 commit b09aad2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/matplotlib/_layoutgrid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def hard_constraints(self):
169169
self.solver.addConstraint(c | 'required')
170170

171171
def add_child(self, child, i=0, j=0):
172-
self.children[i, j] = child
172+
# np.ix_ returns the cross product of i and j indices
173+
self.children[np.ix_(np.atleast_1d(i), np.atleast_1d(j))] = child
173174

174175
def parent_constraints(self):
175176
# constraints that are due to the parent...

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,10 @@ def test_suplabels():
560560
pos = ax.get_tightbbox(fig.canvas.get_renderer())
561561
assert pos.y0 > pos0.y0 + 10.0
562562
assert pos.x0 > pos0.x0 + 10.0
563+
564+
565+
def test_gridspec_addressing():
566+
fig = plt.figure()
567+
gs = fig.add_gridspec(3, 3)
568+
sp = fig.add_subplot(gs[0:, 1:])
569+
fig.draw_without_rendering()

lib/matplotlib/tests/test_figure.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ def test_subfigure_spanning():
10731073
fig.add_subfigure(gs[0, 0]),
10741074
fig.add_subfigure(gs[0:2, 1]),
10751075
fig.add_subfigure(gs[2, 1:3]),
1076+
fig.add_subfigure(gs[0:, 1:])
10761077
]
10771078

10781079
w = 640
@@ -1086,6 +1087,12 @@ def test_subfigure_spanning():
10861087
np.testing.assert_allclose(sub_figs[2].bbox.min, [w / 3, 0])
10871088
np.testing.assert_allclose(sub_figs[2].bbox.max, [w, h / 3])
10881089

1090+
# check here that slicing actually works. Last sub_fig
1091+
# with open slices failed, but only on draw...
1092+
for i in range(4):
1093+
sub_figs[i].add_subplot()
1094+
fig.draw_without_rendering()
1095+
10891096

10901097
@mpl.style.context('mpl20')
10911098
def test_subfigure_ticks():

0 commit comments

Comments
 (0)