我在玩ipython笔记本,我遇到了一个问题。
这段代码%matplotlib inline
帮助我将代码与下面的代码内联起来。
%matplotlib inline
ax1= plt.subplot(2,1,1)
ax1.plot(df.Close,label="sp500")
ax1.plot(ma,label='50MA')
plt.legend()
ax2=plt.subplot(2,1,2, sharex = ax1)
ax2.plot(df['H-L'],label='H-L')
plt.legend()
但是,我无法按照下面的代码进行绘制。
%matplotlib inline
def single_stock(stock_name):
df = pd.read_csv('stocks_date_modified.csv',index_col='time',parse_dates=True)
df = df[df.type == stock_name.lower()]
_500MA= pd.rolling_mean(df['value'],500)
ax1= plt.subplot(2,1,1)
df['close'].plot(label='Price')
plt.legend()
ax2= plt.subplot(2,1,2, sharex = ax1)
_500MA.plot(label='500MA')
plt.legend()
plt.show()
single_stock('bac')
我收到一条错误消息说
UsageError: unrecognized arguments: #this code is to plot inline the notebook
如果没有%matplotlib inline
,我在弹出窗口中就不会出现显示这些情节的问题。
有人能帮我解决这个问题吗?
发布于 2015-01-04 05:43:23
发布于 2015-02-24 01:01:23
如果其他人遇到此错误,您似乎无法在调用IPython Magics的行上有内联注释:
In [9]: %matplotlib inline # allows matplotlib to be inline
UsageError: unrecognized arguments: # allows matplotlib to be inline
在没有评论的情况下,它工作得很好:
In [9]: %matplotlib inline
但是,是的,在启动时用ipython notebook --matplotlib=inline
内联加载matplotlib可能是个明智的举动。
https://stackoverflow.com/questions/27761707
复制相似问题