【发布时间】:2021-12-09 21:15:09
【问题描述】:
我正在尝试在matplotlib 中绘制两个长时间序列。由于我不需要任何子图,因此我没有使用 figure.add_subplot() 方法。
fig = plt.figure()
plt.plot(series1)
plt.plot(series2)
plt.xlabel('Date')
plt.ylabel("Values")
plt.legend(loc='best')
plt.title(Plot title)
fig.autofmt_xdate()
plt.savefig("fig.png", format="png")
但是,上述格式适用于一些短系列,而对于长系列,即使使用 autofmt_xdate() 命令旋转它们,x-ticks 也会重叠很多。在使用子图时我知道ax.set_major_locator() 解决方案,但在使用plt.figure() 时我无法找到类似的解决方案。
【问题讨论】:
标签: python matplotlib plot xticks