2013-12-16 36 views

回答

7

這將繪製小號& P500與每週頻率輕微xticks和網格:

import pandas.io.data as web 
ts = web.DataReader("^GSPC", "yahoo", start=dt.date(2013, 6, 1))[ 'Adj Close' ] 

ax = ts.plot() 
xtick = pd.date_range(start=ts.index.min(), end=ts.index.max(), freq='W') 
ax.set_xticks(xtick, minor=True) 
ax.grid('on', which='minor', axis='x') 
ax.grid('off', which='major', axis='x') 

enter image description here

+0

不錯的一個,但我怎麼能做到這一點使用DataFrame,在我的問題給出?我無法找到相當於ts.index.min()的DataFrame - df.idxmin()會返回一系列... – user2846226

+0

@ user2846226對於DataFrame而言'df.index.min()'也應該可以工作,除非它是多索引 –

+0

確實,用戶錯誤 – user2846226

1

DataFrame.plot()應該從matplotlib返回Axes對象。

因此,與ax = df.plot(...),你可以這樣做:

ax.xaxis.grid(True, which='minor', linestyle='-', linewidth=0.25, ...)

+0

真棒,我沒有意識到plot()返回一個軸對象。所以我猜想一個PNG圖形以scilab模式顯示在IPython筆記本中,因爲筆記本檢測到軸對象的存在? – user2846226

2

也許這功能去年不存在,但在0.19.2版本中可以這樣做:

df.plot(grid=True) 

doc

相關問題