python - 如何将日期时间 x 轴绘制为每月?
问题描述
我想让 xtick 显示从 2019 年 11 月到 2021 年 2 月的所有月份。使用以下代码,xtick 在图中的间隔为 2 个月。
我应该如何将其更改为 1 个月的间隔?
我使用 mdate 修复它,但输出是一样的。
# create figure and axis objects with subplots()
fig,ax = plt.subplots()
# make a plot
ax.plot(df.Date, df.Close, color="yellow",)
# set x-axis label
ax.set_xlabel("date",fontsize=14)
ax.set_xticklabels(df.Date, Rotation=45)
# set y-axis label
ax.set_ylabel("gold price",color="red",fontsize=14)
# twin object for two different y-axis on the sample plot
ax2=ax.twinx()
# make a plot with different y-axis using second axis object
ax2.plot(us_ncase.date,us_ncase.new_cases ,color="red")
ax2.set_ylabel("Covid New Case",color="blue",fontsize=14)
plt.show()
解决方案
推荐阅读
- qt - QML自定义按钮不能发出按下信号,因为它不是一个函数?
- powershell - 如何在 Azure DevOps 中使用 SharePointPnpPowerShellOnline PowerShell 模块?
- javascript - Node.js中的Websocket Server从手机APP访问时返回RSV1错误
- batch-file - 批量删除 .csv 文件中首次出现的特殊字符
- lotus-notes - 有没有办法使用 Notes C API 获取所有用户的私人联系人?
- wordpress - ACF 动态选择值不显示数据
- linux - 如何编写一个 Linux shell 脚本来删除早于 X 天的文件,但按修改时间保留当天的第一个文件?
- php - 如何仅在首页或主页上运行 php?
- python - 在 Python 中将矩阵条目 K_ij 除以 K_ii*K_jj 的快速方法
- css - CSS 不能从 `file:` URL 加载,除非它们以 `.css` 文件扩展名结尾