我有 29 个地块,但我希望将它们排列成更少的行,我该如何在 matplotlib 上做到这一点?
I have 29 plots but I want them to be ordered into less rows, how do I do that on matplotlib?
我有一个 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: (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()
我有一个 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: (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()