我一直在关注'python进行数据分析'.在pg.345,你得到这个代码来绘制各种股票的回报.但是,绘图功能对我不起作用.我得到了FigureCanvasAgg'对象没有属性'invalidate'?
names = ['AAPL','MSFT', 'DELL', 'MS', 'BAC', 'C'] #goog and SF did not work
def get_px(stock, start, end):
return web.get_data_yahoo(stock, start, end)['Adj Close']
px = pd.DataFrame({n: get_px(n, '1/1/2009', '6/1/2012') for n in names})
#fillna method pad uses last valid observation to fill
px = px.asfreq('B').fillna(method='pad')
rets = px.pct_change()
df2 = ((1 + rets).cumprod() - 1)
df2.ix[0] = 1
df2.plot()
Run Code Online (Sandbox Code Playgroud)
更新:完全追溯
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-122-df192c0432be> in <module>()
6 df2.ix[0] = 1
7
----> 8 df2.plot()
//anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in …Run Code Online (Sandbox Code Playgroud)