python - 我有 29 个图,但我希望将它们排列成更少的行,我该如何在 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()
推荐阅读
- angular - Ag-grid 标题中的字体真棒
- java - OpenGL的启动问题
- python - 应用程序未编译为 *. exe(PySide2)
- ios - TableView 从视图层次结构调试器中消失
- java - 我可以缩短这个程序吗
- html - 有没有办法将最新的 css 属性用于该浏览器不支持的其他浏览器
- java - Java BMI 程序
- java - Mapstruct检测修改的节点
- javascript - 使用 formData 和 Axios 上传图片文件
- splunk - Splunk Dashboard 可以使用以下哪个外部组件构建?a)HTML b)CSS 3)XML 4)JavaScript