python - 如何在 matplolib 框架中以日期格式绘制数据框?
问题描述
我有以下数据框
date;A;B;C;D
2017-01-01 00:00:00; 7.45; 52.78; 11.46; 502.44
2017-01-01 01:00:00; 23.95; 47.21; 11.45; 502.42
2017-01-01 02:00:00; 0.96; 44.72; 11.44; 502.44
2017-01-01 03:00:00; 26.67; 42.48; 11.42; 502.42
2017-01-01 04:00:00; 22.42; 38.86; 11.41; 502.40
2017-01-01 05:00:00; 17.50; 39.47; 11.40; 502.39
2017-01-01 06:00:00; 16.78; 42.47; 11.38; 502.38
我想使用日期和列 A 绘制它。特别是我想使用日期自定义 x-ax,但使用固定间隔和格式,仅使用年、月和日。一切都在 matplotlib 框架中以便使用它的功能。
这就是我所做的:
1)读取数据框:
DATAF = pd.read_csv(fnamed+'.dat',sep=';',index_col=0, header = 0)
2)然后我将其绘制为
ax.plot_date(DATAF.index.values,DATAF['A'].values)
结果似乎不可读:图不可读
一种方法是将数据索引转换为数据值,但之后我不知道如何以我想要的格式绘制日期。
提前致谢,
迭戈
解决方案
@ImportanceOfBeingErnest 是对的。这就是我所做的,它似乎有效:
# Converting the index as date
DATAF.index = pd.to_datetime(DATAF.index)
ax.plot(DATAF.index.values,DATAF['A'].values)
非常感谢
推荐阅读
- python - 解释语言如何声明和引用变量?
- crystal-reports - 在特定条件下使用 dateadd
- blazor - c# 文件有类型参数吗?
- python - 熊猫:创建计数累积和列并在条件下重置
- python - 我的第一个 Python 脚本 - 当没有从笔记本电脑连接时,如何让 Python 和任务计划程序在 Windows VM 上工作?
- python - 为什么我得到“一个开放的流对象正在被垃圾收集;显式调用“stream.close()”?
- netmiko - Netmiko / textfsm
- python - print 函数移动输出结果
- python - 如何使用 swagger 为我的 Python Flask 应用程序定义基本端点?
- graphql - 使用纱线运行中继编译器时出现“ENOTDIR”错误