如何在 Matplotlib 中排列嵌套子图?

How to arrange nested subplots in Matplotlib?

我有 3 个垂直排列的地块,代码如下:

plt.figure(1)
plt.subplot(311)
plt.plot(z2, 'blue')
plt.plot(mid2, 'orange')
plt.plot(z3, 'red')
plt.plot(mid3, 'orange')
plt.subplot(312)
plt.plot(z)
plt.plot(mid)
plt.subplot(313)
plt.plot(proportional, "black")

但我想做的是在第一个图 (311) 旁边添加另一个图。我的意思是我想在第一行内有两个地块,然后像以前一样在接下来的两行内有一个地块(我喜欢在一个地块中显示 z2、mid2,在旁边的另一个地块中显示 z3、mid3,都在第一行内) .如果可以,我该怎么做?

我再举个例子。此代码 plt.subplot(324) 将使您的图形变为 3x2 table(3 行和 2 列)并在 "cell 4" 上创建坐标。见下图 所以,如果你想在 "cell 1" 上绘制 z2mid2,那么 plt.subplot(321)plot 它们。

您可能想在 "cell 3" 和 "cell 4" 上绘制 zmid,然后

plt.subplot(312)

(一个 3x1 table 并在 "cell 2" 上创建一个坐标,这相当于一个 3x2 table 在 "cell 3" 和 [=28= 上都有一个坐标])

所以你的代码可能是这样的:

plt.figure(1)

plt.subplot(321)             # "cell 1"
plt.plot(z2, 'blue')
plt.plot(mid2, 'orange')

plt.subplot(322)             # "cell 2"
plt.plot(z3, 'red')
plt.plot(mid3, 'orange')

plt.subplot(312)             # "cell 3" and "cell 4"
plt.plot(z)
plt.plot(mid)

plt.subplot(313)             # "cell 5" and "cell 6"
plt.plot(proportional, "black")