Matplotlib网格xaxis在每日间隔

时间:2013-05-17 14:30:01

标签: matplotlib grid

我有一个每10分钟有一次数据的.csv文件,如下所示:

15/12/2012 13:00,20.83,23.06,23.07,23.12,22.73,22.13,22.79,22.62,13.5,47
15/12/2012 13:10,20.93,23.1,23.1,23.16,22.72,22.18,22.84,22.74,13.5,45.3
15/12/2012 13:20,21.05,23.14,23.12,23.23,22.56,22.23,22.91,22.83,13.4,44.7
15/12/2012 13:30,21.16,23.16,23.07,23.26,22.45,22.23,22.94,22.91,13.3,36.1
15/12/2012 13:40,21.17,23.2,23.06,23.29,22.34,22.24,22.97,22.99,13.3,28.2
15/12/2012 13:50,21.15,23.22,23.06,23.33,22.18,22.24,22.93,23.04,13.3,28.2
15/12/2012 14:00,21.15,23.24,23.07,23.35,22.12,22.28,23,23.1,13.3,25.6
...

我想绘制一个图表,并在每日间隔的x轴上有一个网格。但我只能随机获得一个网格。我做了:

MeasurementData = pd.read_csv('/Users/Silvia/Dropbox/TH/Mediciones/TH_Temperaturas.csv',index_col='Date_Time')
MeasurementData.plot(figsize=(15,10))

我一直在尝试这些命令:

ax.xaxis.set_major_locator(DayLocator())
ax.xaxis.set_major_formatter(DateFormatter("%D"))

但我不能这样做。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您必须确保索引是DatetimeIndex而不是对象索引。这可以通过将parse_dates='Date_Time'传递给pd.read_csv函数来实现,如下所示:

MeasurementData = pd.read_csv('/Users/Silvia/Dropbox/TH/Mediciones/TH_Temperaturas.csv',index_col='Date_Time',parse_dates='Date_Time')

然后你应该能够在每天设置标记。