在Matplotlib中更改X轴日期时间间隔

时间:2019-08-12 18:34:07

标签: python dataframe datetime matplotlib

enter image description here

我浏览了堆栈溢出并发现了一些匹配的问题,但是我从中不能收集太多信息。

我有一个数据集,如上图所示。

数据集由1949年1月到1960年12月的销售数字组成。我想绘制“日期与销售”图。我的代码返回了下图。 enter image description here

X轴仅显示2年的间隔。我希望x轴在1949年1月到1960年12月的日期范围内以均匀的间隔显示(如上面的数据集所示),并以垂直格式旋转以容纳更多的xtick。我该怎么办?

1 个答案:

答案 0 :(得分:1)

https://matplotlib.org/3.1.0/api/dates_api.html#matplotlib.dates.MonthLocator,例如:

import matplotlib.dates as mdates
...
ax.xaxis.set_major_locator(mdates.MonthLocator())
相关问题