Issue 1:
Bug summary

I'm attempting to generate a figure with 9 panels. The top and bottom row are specified as subgridspecs so I could keep their dimensions separate from the constrained layout in the rest of the figure, and not have the positions influenced by axis labels in the middle axes.

Code for reproduction

import matplotlib.pyplot as plt
%matplotlib inline # Working in a jupyter notebook

fig = plt.figure(
constrained_layout=True,
facecolor='None',
figsize=(6,6.5),
)

gs = fig.add_gridspec(3, 3)
gs_0 = gs[0, :].subgridspec(1, 3)
ax_3d_0 = fig.add_subplot(gs_0[0])
ax_3d_1 = fig.add_subplot(gs_0[1], sharex=ax_3d_0, sharey=ax_3d_0)
ax_3d_2 = fig.add_subplot(gs_0[2], sharex=ax_3d_0, sharey=ax_3d_0)

for i, ax in enumerate([ax_3d_0, ax_3d_1, ax_3d_2]):
ax.text(0.5, 0.5, f'gs_0[{i}]',
size=10, ha='center', va='center')

gs_lo = gs[2, :].subgridspec(1, 3)
ax_leg_0 = fig.add_subplot(gs_lo[0])
ax_leg_1 = fig.add_subplot(gs_lo[1])
ax_leg_2 = fig.add_subplot(gs_lo[2])

for i, ax in enumerate([ax_leg_0, ax_leg_1, ax_leg_2]):
ax.text(0.5, 0.5, f'gs_lo[{i}]',
size=10, ha='center', va='center')

Actual outcome

Expected outcome

Additional information

In a previous version (python 3.6.10, matplotlib 3.2.2), I had no issues.

In my current version (python 3.8. matplotlib 3.5.0) all the subgridspec axes end up on top of each other (see actual outcome)

Operating system

osx

Matplotlib Version

matplotlib 3.5.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.8.12

Jupyter version

3.2.5

Installation

conda

Issue 2:
Bug summary

When plotting a figure with constrained_layout and subgrids, rows with the same arguments are being plot on top of each other.

Code for reproduction

import matplotlib.pyplot as plt

Fig = plt.figure(constrained_layout=True)

GS = Fig.add_gridspec(3,1)
GSRows = [
GS[0].subgridspec(1,5, width_ratios=(0.2, 1, 1, 1, 0.2)),
GS[1].subgridspec(1,5, width_ratios=(0.2, 1, 0.2, 1, 1)),
GS[2].subgridspec(1,5, width_ratios=(0.2, 1, 1, 1, 0.2)),
# GS[2].subgridspec(1,5, width_ratios=(0.199999, 1, 1, 1, 0.2)),
]

Axes = [
Fig.add_subplot(GSRows[0][1]),
Fig.add_subplot(GSRows[0][2]),
Fig.add_subplot(GSRows[0][3]),

Fig.add_subplot(GSRows[1][1]),
Fig.add_subplot(GSRows[1][3]),
Fig.add_subplot(GSRows[1][4]),

Fig.add_subplot(GSRows[2][1]),
Fig.add_subplot(GSRows[2][2]),
Fig.add_subplot(GSRows[2][3]),
]

Fig.savefig('ActualOutcome.jpg')
# Fig.savefig('ExpectedOutcome.jpg')

plt.show()

Actual outcome

Expected outcome

(Changed the third row first column width ratio from 0.2 to 0.199999, see commented line)

Additional information

In the example, the figure has 3 rows and 5 columns with different width ratios. Rows 1 and 3 have the same width ratios, while row 2 has a different width ratio. Note that rows 1 and 3 are merged (row 3 is drawn on top of row 1; Actual outcome image). Note also that if the subgrids are all different (see commented lines in code example changing the width ratio of row 3 from 0.2 to 0.199999) all three rows are drawn as expected.

This was not the case at least until 3.4.3, where even if the rows are equal, they are drawn at their expected places.

Operating system

Gentoo

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

Python 3.9.9

Jupyter version

6.4.6

Installation

Linux package manager