Skip to content

Commit e39fbb6

Browse files
authored
Merge pull request #20022 from meeseeksmachine/auto-backport-of-pr-19949-on-v3.4.x
Backport PR #19949 on branch v3.4.x (FIX: subfigure indexing error)
2 parents 2035677 + dc8fa2d commit e39fbb6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/matplotlib/figure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2037,11 +2037,11 @@ def _redo_transform_rel_fig(self, bbox=None):
20372037

20382038
x0 = 0
20392039
if not self._subplotspec.is_first_col():
2040-
x0 += np.sum(wr[self._subplotspec.colspan.start - 1]) / np.sum(wr)
2040+
x0 += np.sum(wr[:self._subplotspec.colspan.start]) / np.sum(wr)
20412041

20422042
y0 = 0
20432043
if not self._subplotspec.is_last_row():
2044-
y0 += 1 - (np.sum(hr[self._subplotspec.rowspan.stop - 1]) /
2044+
y0 += 1 - (np.sum(hr[:self._subplotspec.rowspan.stop]) /
20452045
np.sum(hr))
20462046

20472047
if self.bbox_relative is None:

lib/matplotlib/tests/test_figure.py

+22
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,28 @@ def test_subfigure_double():
998998
axsRight = subfigs[1].subplots(2, 2)
999999

10001000

1001+
def test_subfigure_spanning():
1002+
# test that subfigures get laid out properly...
1003+
fig = plt.figure(constrained_layout=True)
1004+
gs = fig.add_gridspec(3, 3)
1005+
sub_figs = [
1006+
fig.add_subfigure(gs[0, 0]),
1007+
fig.add_subfigure(gs[0:2, 1]),
1008+
fig.add_subfigure(gs[2, 1:3]),
1009+
]
1010+
1011+
w = 640
1012+
h = 480
1013+
np.testing.assert_allclose(sub_figs[0].bbox.min, [0., h * 2/3])
1014+
np.testing.assert_allclose(sub_figs[0].bbox.max, [w / 3, h])
1015+
1016+
np.testing.assert_allclose(sub_figs[1].bbox.min, [w / 3, h / 3])
1017+
np.testing.assert_allclose(sub_figs[1].bbox.max, [w * 2/3, h])
1018+
1019+
np.testing.assert_allclose(sub_figs[2].bbox.min, [w / 3, 0])
1020+
np.testing.assert_allclose(sub_figs[2].bbox.max, [w, h / 3])
1021+
1022+
10011023
def test_add_subplot_kwargs():
10021024
# fig.add_subplot() always creates new axes, even if axes kwargs differ.
10031025
fig = plt.figure()

0 commit comments

Comments
 (0)