单个图中的多个 gridspec 布局

Multiple gridspec layout in a single plot

使用 GridSpec 制作子图,我希望在我的网格中有不同的 hspace 或 wspace。我在某处读到,最简单的方法是为单个图创建不同的网格,这样我的参数 hspace 和 wspace 就可以有不同的值。

但是,我可以堆叠不同网格的唯一情况是粘贴文档中给出的示例:https://matplotlib.org/users/gridspec.html#adjust-gridspec-layout

谁能解释一下为什么在下面的代码中只显示最后一个网格?目标只是垂直堆叠两个网格。

gs_top = gridspec.GridSpec(2, 2)

ax1 = plt.subplot(gs_top[0:2, 0:2])
#ax2 = plt.subplot(gs_top[0:2, 1])

gs_bottom = gridspec.GridSpec(2, 2)

ax3 = plt.subplot(gs_bottom[0, 0])
ax4 = plt.subplot(gs_bottom[0, 1])
ax5 = plt.subplot(gs_bottom[1, 0:2])

真不懂怎么控制"grid stacking" ... 在文档的示例中,python 如何知道网格是水平堆叠而不是垂直堆叠的?

谢谢!

the example中,第一个网格在图的左侧,因为它的子图参数是这样设置的

gs1.update(left=0.05, right=0.48)

它从图形宽度的 5% 处开始,到图形宽度的 48% 处结束。 第二格,

gs2.update(left=0.55, right=0.98)

从 55% 开始,到 98% 结束。 100% 将是正确的图形边缘。

您可以使用 bottomtop 代替 leftright 进行垂直定位。