Python 我有29个绘图,但我希望将它们排序为更少的行,如何在matplotlib上做到这一点?
我有一个for循环,在那里我画了29个图。。。如何使绘图并排排列(例如4x7加上一行1个绘图),而不是全部垂直排列Python 我有29个绘图,但我希望将它们排序为更少的行,如何在matplotlib上做到这一点?,python,numpy,matplotlib,jupyter,Python,Numpy,Matplotlib,Jupyter,我有一个for循环,在那里我画了29个图。。。如何使绘图并排排列(例如4x7加上一行1个绘图),而不是全部垂直排列 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
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()
您需要使用
ax
而不是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()
fig,ax=plt.子批次(nrows=…,ncols=…)
?嗯。。完全不起作用(非常感谢!!这真的很有帮助。为了使体形更大,我应该做:ax=plt.subplot(5,6,i+1,figsize(15,10))不,把plt.figsize=(15,10))
放在循环的之前和之外。