How to arrange nested subplots in Matplotlib?

Viewed 1936

I have 3 plots arranged vertically with the following code:

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")

But what I want to do is adding another plot next to the first plot(311). I mean I want to have two plots inside the first row, then one plot inside next two rows as before(I like to show z2,mid2 in one plot and z3,mid3 in other plot next to that, both inside the first row). If is it possible, how can I do that?

1 Answers

I will make another example. This code plt.subplot(324) will make your figure become a 3x2 table (3 rows and 2 columns) and make a coordinate on the "cell 4". See the image belowthe "table" So, if you want to plot z2 and mid2 on "cell 1", then plt.subplot(321) and plot them.

You may want to plot z and mid on both the "cell 3" and "cell 4", then

plt.subplot(312)

(a 3x1 table and make a coordinate on "cell 2", which is equivalent to a 3x2 table with a coordinate on both "cell 3" and "cell 4")

So your code might be something like:

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")
Related