Skip to content

FIX: spanning subfigures #21481

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion lib/matplotlib/_layoutgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def hard_constraints(self):
self.solver.addConstraint(c | 'required')

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

def parent_constraints(self):
# constraints that are due to the parent...
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_constrainedlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,10 @@ def test_suplabels():
pos = ax.get_tightbbox(fig.canvas.get_renderer())
assert pos.y0 > pos0.y0 + 10.0
assert pos.x0 > pos0.x0 + 10.0


def test_gridspec_addressing():
fig = plt.figure()
gs = fig.add_gridspec(3, 3)
sp = fig.add_subplot(gs[0:, 1:])
fig.draw_without_rendering()
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ def test_subfigure_spanning():
fig.add_subfigure(gs[0, 0]),
fig.add_subfigure(gs[0:2, 1]),
fig.add_subfigure(gs[2, 1:3]),
fig.add_subfigure(gs[0:, 1:])
]

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

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


@mpl.style.context('mpl20')
def test_subfigure_ticks():
Expand Down