python - 在 python matplotlib 中绘制 x 轴的空格日期
问题描述
我在 python 中有一个时间序列图,它产生了我想要的结果,除了轴不太正确......
下图:
我只是想把它隔开整个情节图......
我的代码如下:
x2 = all_sentiment['date']
x2 = pd.Series(list(set(x2)))
y2 = all_sentiment['sent_count']
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(20, 10))
axes.plot(range(len(s_pos)), s_pos, linewidth=2, color='green')
axes.plot(range(len(s_neg)), s_neg, linewidth=2, color='red')
#axes.set_xticks(x2.index.tolist())
axes.set_xticks(np.arange(len(x2.index.tolist())))
axes.set_xticklabels([date.strftime("%Y-%m-%d") for date in x2])
axes.margins = 0
axes.set_xlabel('Date/Time')
axes.set_ylabel('Num of Tweets')
axes.set_title('Number of Tweets Over Time - Positive and Negative')
axes.set_xlim(0, len(y2))
axes.legend(loc="upper right", labels=['Positive', 'Negative'])
fig.subplots_adjust(hspace=1)
plt.show()
你能指出我在这里做错了什么吗?
非常感谢。
解决方案
推荐阅读
- reactjs - 如何在玩笑测试中共享设置和拆卸?
- database - 我可以删除显示无法连接的 postgres 数据库吗?
- python - 匹配 Pandas DataFrame 时出现“KeyError: True”
- perl - 如何获取已知 Unicode 字符名称的列表
- firebase - 异步函数:未来
在颤振中布尔? - r - 循环回归和存储截距、斜率等
- python - PermissionError:[错误 13] 权限被拒绝:scr.png
- database - 如何从依赖于节点类型的 csv 在 neo4j/Cypher 中创建关系?
- pine-script - 如何检查蜡烛是否是 Pine-Script 中最大的蜡烛?
- algorithm - 查找给定 x 值的多项式序列