python - 如何在 Matplotlib 中正确设置日期?
问题描述
x 轴上的年份不正确;表格格式为 YY-MM-DD。我错过了代码的哪一部分?你能提个建议吗?
date new_sentiment count
0 2020-03-06 POSITIVE 1
1 2020-03-17 NEGATIVE 2
2 2020-03-18 NEUTRAL 1
3 2020-03-21 NEUTRAL 1
4 2020-03-23 NEUTRAL 1
... ... ... ...
831 2021-05-30 NEGATIVE 92
832 2021-05-30 NEUTRAL 84
833 2021-05-30 POSITIVE 26
834 2021-05-31 NEGATIVE 19
835 2021-05-31 NEUTRAL 7
我的代码
sns.lineplot(data=data, x='date', y='count', hue='new_sentiment')
sns.set_style("whitegrid", {
"ytick.major.size": 0.1,
"ytick.minor.size": 0.05,
'grid.linestyle': 'solid'
})
plt.legend(bbox_to_anchor=(1.04,1), loc="upper left")
plt.setp(plt.gca().xaxis.get_majorticklabels(),rotation=90)
myFmt = mdates.DateFormatter('%d-%b-%Y')
plt.gca().xaxis.set_major_formatter(myFmt)
plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=16))
plt.xlim('2020-03-06','2021-06-15')
plt.savefig('04_#clean_sentiment_count_2020_2021.tiff', dpi=300, format='tiff', bbox_inches='tight')
解决方案
推荐阅读
- java - 为什么方法重载解析必须在 JAVA 的编译时完成?
- java - 为什么我会得到
预期的 - javascript - AngularJS webapp 仅在 Chrome 70 上中断
- javascript - ReferenceError: jurusan 没有在 Angular 中用 Nodejs 定义
- javascript - 带有 uikit css 框架的响应式导航栏
- list - 使用没有“::”运算符的“cons” ocaml
- python - 遍历 Pandas 数据框单元格以根据其他单元格值计算运行总计
- sql - 如何从下面的查询中获取具有 id 和第二天日期的行号分区?
- tensorboard - Tensorboard 假设分析工具
- android - 滚动 ListView customAdabter 时微调器数据将消失