2017-09-05 4 views
1

私はこの実行すると、次のデータフレームパンダ二軸

Date  A   B 
0 2017-05-31 17453139 5.865738 
1 2017-06-30 17425164 5.272728 
2 2017-07-31 17480789 4.843094 

を持っている:

df.plot(x='Date', y='A') 
df.B.plot(secondary_y=True) 

を私は次のエラーを取得:

> appdata\local\programs\python\python36\lib\site-packages\pandas\plotting\_timeseries.py 
> in format_dateaxis(subplot, freq, index) 
>  335    TimeSeries_TimedeltaFormatter()) 
>  336  else: 
> --> 337   raise TypeError('index type not supported') 
>  338 
>  339  pylab.draw_if_interactive() 
> 
> TypeError: index type not supported 

をそして、私のグラフは、このようになりますエラーの下(青と赤が重なるはずです): Blue and red should overlap

答えて

1

IIUC:

ax = df.plot('Date','A') 
ax1 = ax.twinx() 
df.plot('Date','B',ax=ax1, color='r') 

出力:

enter image description here

それとも、パンダプロットでsecondary_yを使用することができます。

ax = df.plot('Date','A') 
df.plot('Date','B',secondary_y=True, ax=ax) 

出力:

enter image description here

関連する問題