Python:更改Pandas Plot的xticks时间

时间:2015-02-03 19:56:56

标签: python pandas

enter image description here

我使用应用于Pandas DataFrame的绘图函数生成上面的图片,例如df.plot()。我的问题是如何更改xticks,使xticks上显示的时间为9:30:00, 11:00:00, 12:30:00, 2:00:00, 3:30:00, 4:00:00?我df的索引是:Index([09:40:00, 09:45:00, 09:50:00, 09:55:00, 10:00:00, 10:05:00, ... ]

1 个答案:

答案 0 :(得分:2)

绘制系列/数据框时,您始终可以设置xticks参数。

x = [1,2,3,4,5,6]
y = [10, 14, 23, 34,16,9]

df = pd.DataFrame({'x':x, 'y':y})
df.plot(xticks=[1.5, 2.5, 3.5, 4.5, 5.5])

如果我没有设置xticks,则情节如下:

enter image description here

如果我如上所示设置xticks,则情节如下:

enter image description here

显然,新的xticks包含的值大于x值,但我确定你明白了。另外,请查看pandas文档here以获取更多信息。