Reputation: 839
I have a for loop where I made 29 plots... how do I make the plots ordered side by side (say 4x7 plus one additional row with 1 plot) instead of all vertical?
for i in range(int(len(lsds_monthly)/24)):
plt.plot(time_months[i*24: (i+1)*24],lsds_monthly[i*24: (i+1)*24])
plt.xticks(np.arange(min(time_months[i*24: (i+1)*24]),max(time_months[i*24: (i+1)*24]),.15), rotation=35)
plt.grid()
plt.title('LSDS Monthly Data')
plt.show()
Upvotes: 0
Views: 55
Reputation: 150785
You need to plot using ax
instead of plt
:
for i in range(int(len(lsds_monthly)/24)):
# add a new subplot
ax = plt.subplot(5, 6, i+1)
# plot on the subplot
ax.plot(time_months[i*24: (i+1)*24],lsds_monthly[i*24: (i+1)*24])
# other formatting
ax.set_xticks(np.arange(min(time_months[i*24: (i+1)*24]),max(time_months[i*24: (i+1)*24]),.15), rotation=35)
ax.grid()
ax.title('LSDS Monthly Data')
plt.show()
Upvotes: 1