python - 如何绘制分散的时间戳
问题描述
我试图随着时间的推移绘制冠状病毒病例,但是当我运行我的代码时,所有时间戳都被挤压在一起。我希望将它们分开,以便您可以实际阅读索引并查看时间。
这是我用来绘制图形的代码:
washcases.plot.bar(rot=15, title="Cases per Day in Washtenaw County")
,我的数据如下所示:
2020-03-01 0
2020-03-02 0
2020-03-03 0
2020-03-04 0
2020-03-05 3
2020-03-06 1
2020-03-07 5
谁能帮我用更易读的时间戳来绘制我的数据图?谢谢!
我看过的帖子:
解决方案
您可以减少 x 轴上显示的标签数量,如下所示:
import matplotlib.pyplot as plt
# your code for loading the data and plotting
# get the current axis
ax = plt.gca()
# set the number of labels (e.g. 10)
ax.xaxis.set_major_locator(plt.MaxNLocator(10))
plt.show()
推荐阅读
- java - 将数组作为参数传递;使用扫描器类在 Java 中使用用户输入设置数组
- python - 如何在 Python 中连接多个(超过 2 个)二维数组?
- azure-devops - Azure devops 管道:无法使用 SourceVersion 变量部署特定变更集
- html - 如何将元素与容器的顶部和底部对齐?
- javascript - 是否可以将 D3.tree() 与包含父母而不是孩子的数据集一起使用?
- environment-variables - Postman 中的环境变量
- java - Android ListView 项目太大不知道为什么
- c++ - 强制 CMake 重建预编译的头文件
- java - 运行 docker 容器“NoClassDefFoundError”时出错
- google-data-studio - 在 Google Data Studio 中可视化仪表板时动态创建/访问图表