-- Python 3.5 --
我正在做一个项目,我可以将很少的数据映射到图表中 在图表上可以从 7 点到 200 点不等。 X 轴包含日期,当图表上的记录数量增加时,日期会聚集在一起,这使得图表有点不可读。
无论如何,无论有多少条记录,我都可以将 x 轴上的刻度限制为 4(绘制时间)。
我尝试使用 locator_params()
但它不随时间变化。
我们将不胜感激任何建议或解决方法。
最佳答案
使用 matplotlib 绘制日期时,您想使用 matplotlib.dates
中的定位器和格式化程序.
在这里,您可以使用 AutoDateLocator
matplotlib.dates.AutoDateLocator(tz=None, minticks=4, maxticks=4)
在哪里
maxticks
is the maximum number of ticks desired, which controls any interval between ticks (ticking every other, every 3, etc.).
有关如何使用这些定位器和格式化程序的示例已给出 on the matplotlib page .
关于python - 如何在 matplotlib python 中设置确切的日期刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45887850/