python - 如何将 Xaxis(次)的格式更改为其他格式?Python - 熊猫 - Matplotlib
问题描述
我尝试创建条形图,但 X 轴格式有问题。在图中,我有年月日 00:00:00。但我只想要年月,所以我尝试了这段代码:
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.dates import DateFormatter
ax = df_graph.plot(kind='bar', figsize=(12, 8), legend=False)
plt.title('Groups Unavailability by Month')
plt.ylabel('Unavailability (hours)')
plt.xlabel('Date (Year-Month)')
hfmt = mdates.DateFormatter('%Y-%m')
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(hfmt)
plt.xticks(rotation=0)
三行 hftm、major_locator、major_formatter 没有效果……
谢谢你的时间 !
解决方案
推荐阅读
- machine-learning - 如何结合光谱聚类的分裂运行以获得巨大的亲和矩阵
- php - 从不同的数组php中删除重复的值
- r - 尝试通过从数据库传递 URL 来抓取数据但抛出错误
- java - log4j2没有写入文件
- c# - 时间:2019-01-10 标签:c#mongosortandsort(set by set)
- php - 使用 Flysystem 处理大文件
- python - 在python3.5中将字符串转换为元组
- javascript - ng-app中的三元运算符?
- auth0 - Auth0:如何获得规则中的所有范围?
- android - 如何在 Android 8(Oreo) 中每 5 分钟启动一次调度程序,而不会失败 - (尝试过的 Jobscheduler 最小限制为 15 分钟,不可靠)