Fitting multiple sets of subplots into one figure

Viewed 1390

Is it at all possible for me to make one set of subplots (with 2 plots) in a for loop that runs three times, and then fit the three sets of subplots into one main figure. The whole point of this is to be able to have 6 plots on one figure, but have a space between every other plot. I know how to have 6 plots in one figure, but I can only put space between every plot instead of every other plot. I hope my question makes sense. As for the data that I'm using, it is a pretty basic data set I'm using for practice right now. Each pair of plot share the same x-axis, which is why I don't want a space between them.

import matplotlib.pyplot as plt

x1 = [0,1,2,3,4,5]
y1 = [i*2 for i in x1]
y2 = [i*3 for i in x1]

x2 = [4,8,12,16,20]
y3 = [i*5 for i in x2]
y4 = [i*3 for i in x2]

x3 = [0,1,2,3,4,5]
y5 = [i*4 for i in x3]
y6 = [i*7 for i in x3]

fig = plt.figure(1,figsize=(5,5))

ax1 = plt.subplot(611)
ax1.plot(x1,y1)

ax2 = plt.subplot(612)
ax2.plot(x1,y2)

ax3 = plt.subplot(613)
ax3.plot(x2,y3)

ax4 = plt.subplot(614)
ax4.plot(x2,y4)

ax5 = plt.subplot(615)
ax5.plot(x3,y5)

ax6 = plt.subplot(616)
ax6.plot(x3,y6)

fig.subplots_adjust(hspace=0.5)

plt.show()

This is what I get:

enter image description here

1 Answers
Related