<h3 dir="auto">Bug summary</h3>
<p dir="auto">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.</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-c1">%</span><span class="pl-s1">matplotlib</span> <span class="pl-s1">inline</span> <span class="pl-c"># Working in a jupyter notebook</span>

<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(
    <span class="pl-s1">constrained_layout</span><span class="pl-c1">=</span><span class="pl-c1">True</span>,
    <span class="pl-s1">facecolor</span><span class="pl-c1">=</span><span class="pl-s">'None'</span>,
    <span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-c1">6</span>,<span class="pl-c1">6.5</span>),
    )

<span class="pl-s1">gs</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_gridspec</span>(<span class="pl-c1">3</span>, <span class="pl-c1">3</span>)
<span class="pl-s1">gs_0</span> <span class="pl-c1">=</span> <span class="pl-s1">gs</span>[<span class="pl-c1">0</span>, :].<span class="pl-en">subgridspec</span>(<span class="pl-c1">1</span>, <span class="pl-c1">3</span>)
<span class="pl-s1">ax_3d_0</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-s1">gs_0</span>[<span class="pl-c1">0</span>])
<span class="pl-s1">ax_3d_1</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-s1">gs_0</span>[<span class="pl-c1">1</span>], <span class="pl-s1">sharex</span><span class="pl-c1">=</span><span class="pl-s1">ax_3d_0</span>, <span class="pl-s1">sharey</span><span class="pl-c1">=</span><span class="pl-s1">ax_3d_0</span>)
<span class="pl-s1">ax_3d_2</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-s1">gs_0</span>[<span class="pl-c1">2</span>], <span class="pl-s1">sharex</span><span class="pl-c1">=</span><span class="pl-s1">ax_3d_0</span>, <span class="pl-s1">sharey</span><span class="pl-c1">=</span><span class="pl-s1">ax_3d_0</span>)


<span class="pl-k">for</span> <span class="pl-s1">i</span>, <span class="pl-s1">ax</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>([<span class="pl-s1">ax_3d_0</span>, <span class="pl-s1">ax_3d_1</span>, <span class="pl-s1">ax_3d_2</span>]):
    <span class="pl-s1">ax</span>.<span class="pl-en">text</span>(<span class="pl-c1">0.5</span>, <span class="pl-c1">0.5</span>, <span class="pl-s">f'gs_0[<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">i</span><span class="pl-kos">}</span></span>]'</span>,
            <span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-c1">10</span>, <span class="pl-s1">ha</span><span class="pl-c1">=</span><span class="pl-s">'center'</span>, <span class="pl-s1">va</span><span class="pl-c1">=</span><span class="pl-s">'center'</span>)


<span class="pl-s1">gs_lo</span> <span class="pl-c1">=</span> <span class="pl-s1">gs</span>[<span class="pl-c1">2</span>, :].<span class="pl-en">subgridspec</span>(<span class="pl-c1">1</span>, <span class="pl-c1">3</span>)    
<span class="pl-s1">ax_leg_0</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-s1">gs_lo</span>[<span class="pl-c1">0</span>])
<span class="pl-s1">ax_leg_1</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-s1">gs_lo</span>[<span class="pl-c1">1</span>])
<span class="pl-s1">ax_leg_2</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-s1">gs_lo</span>[<span class="pl-c1">2</span>])

<span class="pl-k">for</span> <span class="pl-s1">i</span>, <span class="pl-s1">ax</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>([<span class="pl-s1">ax_leg_0</span>, <span class="pl-s1">ax_leg_1</span>, <span class="pl-s1">ax_leg_2</span>]):
    <span class="pl-s1">ax</span>.<span class="pl-en">text</span>(<span class="pl-c1">0.5</span>, <span class="pl-c1">0.5</span>, <span class="pl-s">f'gs_lo[<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">i</span><span class="pl-kos">}</span></span>]'</span>,
            <span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-c1">10</span>, <span class="pl-s1">ha</span><span class="pl-c1">=</span><span class="pl-s">'center'</span>, <span class="pl-s1">va</span><span class="pl-c1">=</span><span class="pl-s">'center'</span>)</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5534846/150771687-0ec47dbb-88e1-4a59-a097-19f5c17e9315.png"><img src="https://user-images.githubusercontent.com/5534846/150771687-0ec47dbb-88e1-4a59-a097-19f5c17e9315.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5534846/150787811-d7066875-7406-4e27-9057-08f8dc6fb3cd.png"><img src="https://user-images.githubusercontent.com/5534846/150787811-d7066875-7406-4e27-9057-08f8dc6fb3cd.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">In a previous version (python 3.6.10, matplotlib 3.2.2), I had no issues.</p>
<p dir="auto">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)</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">osx</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">matplotlib 3.5.0</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">module://matplotlib_inline.backend_inline</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.8.12</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto">3.2.5</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">conda</p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">When plotting a figure with <code class="notranslate">constrained_layout</code> and subgrids, rows with the same arguments are being plot on top of each other.</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-v">Fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s1">constrained_layout</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-v">GS</span> <span class="pl-c1">=</span> <span class="pl-v">Fig</span>.<span class="pl-en">add_gridspec</span>(<span class="pl-c1">3</span>,<span class="pl-c1">1</span>)
<span class="pl-v">GSRows</span> <span class="pl-c1">=</span>  [
    <span class="pl-v">GS</span>[<span class="pl-c1">0</span>].<span class="pl-en">subgridspec</span>(<span class="pl-c1">1</span>,<span class="pl-c1">5</span>, <span class="pl-s1">width_ratios</span><span class="pl-c1">=</span>(<span class="pl-c1">0.2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0.2</span>)),
    <span class="pl-v">GS</span>[<span class="pl-c1">1</span>].<span class="pl-en">subgridspec</span>(<span class="pl-c1">1</span>,<span class="pl-c1">5</span>, <span class="pl-s1">width_ratios</span><span class="pl-c1">=</span>(<span class="pl-c1">0.2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0.2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>)),
    <span class="pl-v">GS</span>[<span class="pl-c1">2</span>].<span class="pl-en">subgridspec</span>(<span class="pl-c1">1</span>,<span class="pl-c1">5</span>, <span class="pl-s1">width_ratios</span><span class="pl-c1">=</span>(<span class="pl-c1">0.2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0.2</span>)),
    <span class="pl-c"># GS[2].subgridspec(1,5, width_ratios=(0.199999, 1, 1, 1, 0.2)),</span>
]

<span class="pl-v">Axes</span> <span class="pl-c1">=</span> [
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">0</span>][<span class="pl-c1">1</span>]),
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">0</span>][<span class="pl-c1">2</span>]),
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">0</span>][<span class="pl-c1">3</span>]),

    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">1</span>][<span class="pl-c1">1</span>]),
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">1</span>][<span class="pl-c1">3</span>]),
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">1</span>][<span class="pl-c1">4</span>]),

    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">2</span>][<span class="pl-c1">1</span>]),
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">2</span>][<span class="pl-c1">2</span>]),
    <span class="pl-v">Fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-v">GSRows</span>[<span class="pl-c1">2</span>][<span class="pl-c1">3</span>]),
]

<span class="pl-v">Fig</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'ActualOutcome.jpg'</span>)
<span class="pl-c"># Fig.savefig('ExpectedOutcome.jpg')</span>

<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/3614913/148546484-06b15af6-7708-47f3-87db-bfab8db22ae4.jpg"><img src="https://user-images.githubusercontent.com/3614913/148546484-06b15af6-7708-47f3-87db-bfab8db22ae4.jpg" alt="ActualOutcome" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">(Changed the third row first column width ratio from 0.2 to 0.199999, see commented line)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/3614913/148546867-1ec6a3bb-f031-4460-81ba-68beda49e069.jpg"><img src="https://user-images.githubusercontent.com/3614913/148546867-1ec6a3bb-f031-4460-81ba-68beda49e069.jpg" alt="ExpectedOutcome" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">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.</p>
<p dir="auto">This was not the case at least until <code class="notranslate">3.4.3</code>, where even if the rows are equal, they are drawn at their expected places.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Gentoo</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.1</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">TkAgg</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">Python 3.9.9</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto">6.4.6</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">Linux package manager</p>