与这个问题非常相似,但不同之处在于我的身材可以达到需要的大小.
我需要在matplotlib中生成一堆垂直堆叠的图.结果将使用figsave保存并在网页上查看,因此我不关心最终图像的高度,只要子图间隔开,这样它们就不会重叠.
无论我有多大的数字,子图总是似乎重叠.
我的代码目前看起来像
import matplotlib.pyplot as plt
import my_other_module
titles, x_lists, y_lists = my_other_module.get_data()
fig = plt.figure(figsize=(10,60))
for i, y_list in enumerate(y_lists):
plt.subplot(len(titles), 1, i)
plt.xlabel("Some X label")
plt.ylabel("Some Y label")
plt.title(titles[i])
plt.plot(x_lists[i],y_list)
fig.savefig('out.png', dpi=100)
Run Code Online (Sandbox Code Playgroud) 希望在绘制的图形之间添加垂直空间以允许X轴标签显示:
每个图形都需要有空间来显示当天,目前最后两个图形是唯一显示的图形,因为图形与它重叠.
同样好奇的是,我是否真的可以删除X轴的凹口标签,用于周四/周五标记的图形,即底部X轴是唯一显示的图形.对于Y轴也是如此,但只有左侧的图表显示了比例.
*遗憾的是,由于我没有足够的代表,我无法发布图片来展示这一点.
代码段:
import mathlib.pyplot as pyplot
fig = pyplot.figure()
ax1 = fig.add_subplot(4,2,1)
ax1.set_yscale('log')
ax2 = fig.add_subplot(4,2,2, sharex=ax1, sharey=ax1)
ax3 = fig.add_subplot(4,2,3, sharex=ax2, sharey=ax2)
ax4 = fig.add_subplot(4,2,4, sharex=ax3, sharey=ax3)
ax5 = fig.add_subplot(4,2,5, sharex=ax4, sharey=ax4)
ax6 = fig.add_subplot(4,2,6, sharex=ax5, sharey=ax5)
ax7 = fig.add_subplot(4,2,7, sharex=ax6, sharey=ax6)
ax1.plot(no_dict["Saturday"],'k.-',label='Saturday')
ax1.set_xlabel('Saturday')
ax1.axis([0,24,0,10000])
pyplot.suptitle('Title')
pyplot.xlabel('Hour in 24 Hour Format')
ax2.plot(no_dict["Sunday"],'b.-',label='Sunday')
ax2.set_xlabel('Sunday')
...
Run Code Online (Sandbox Code Playgroud)
