<p>首先,有一个更容易解决你原来的问题的办法,只要你能接受稍微不精确。只需在调用<code>tight_layout</code>之后将子块的顶部范围重置为默认值:</p>
<pre><code>fig, axes = plt.subplots(ncols=2, sharey=True)
plt.setp(axes, title='Test')
fig.suptitle('An overall title', size=20)
fig.tight_layout()
fig.subplots_adjust(top=0.9)
plt.show()
</code></pre>
<p><img src="https://i.stack.imgur.com/kFjJo.png" alt="enter image description here"/></p>
<hr/>
<p>但是,要回答您的问题,您需要在稍低的级别创建子块才能使用gridspec。如果要复制共享轴的隐藏,如<code>subplots</code>所做的,则需要使用<code>sharey</code>参数对<a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.add_subplot">^{<cd4>}</a>进行手动操作,并使用<code>plt.setp(ax.get_yticklabels(), visible=False)</code>隐藏重复的记号。</p>
<p>例如:</p>
<pre><code>import matplotlib.pyplot as plt
from matplotlib import gridspec
fig = plt.figure()
gs = gridspec.GridSpec(1,2)
ax1 = fig.add_subplot(gs[0])
ax2 = fig.add_subplot(gs[1], sharey=ax1)
plt.setp(ax2.get_yticklabels(), visible=False)
plt.setp([ax1, ax2], title='Test')
fig.suptitle('An overall title', size=20)
gs.tight_layout(fig, rect=[0, 0, 1, 0.97])
plt.show()
</code></pre>
<p><img src="https://i.stack.imgur.com/QNcbh.png" alt="enter image description here"/></p>