在pandas中绘制两个数字列,在x轴上显示日期

时间:2017-06-28 17:59:09

标签: python pandas datetime matplotlib

Currently I have this graph:

从这段代码:     data.Date = pd.to_datetime(data.Date)     data.sort_values(' Date',inplace = True)

data['mean_Kincaid'] = data.Kincaid.rolling(250, 
min_periods=1).mean()
data.plot(x='Date', y='mean_Kincaid',  
legend=False, title="Kincaid scores over time")

使用此行:

data['mean_Score'] = data.Score.rolling(250, min_periods=1).mean()

我想绘制' mean_Score'优选地用虚线在同一图表上。我的尝试:

data.plot(x='Date', y='mean_Kincaid', y = 'mean_Score',  legend=False, 
title="Kincaid scores over time")

1 个答案:

答案 0 :(得分:1)

使用从第一个图中获取轴手柄,然后使用pandas.DataFrame.plot中的ax参数绘制相同轴上的第二行:

ax = data.plot(x='Data', y='mean_Kincaid',legend=False, title="Kincaid score over time")
data.plot(x='Date', y='mean_Score', ax=ax)