user3368526 user3368526 - 1 year ago 57
Python Question

Cannot plot inline with ipython notebook

I'm playing with ipython notebook and I got a problem.

This code

%matplotlib inline
helped me to plot inline with the code below.

%matplotlib inline
ax1= plt.subplot(2,1,1)

ax2=plt.subplot(2,1,2, sharex = ax1)

However, I cannot plot inline with the code below.

%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)

ax2= plt.subplot(2,1,2, sharex = ax1)


I got an error message saying

UsageError: unrecognized arguments: #this code is to plot inline the notebook

Without the
%matplotlib inline
I don't have problem showing the plots but in the popup window.

Could someone help me to solve this?

Answer Source

You can run your notebook with:

ipython notebook --matplotlib=inline

And to avoid repetitive typing on everytime you use notebook, you can create a notebook profile READ HERE. You can also read this relevant SO Answer with regards to how to write your configuration file.

Or if you're using some sort of shortcut key to invoke your notebook (like in Mac/Linux), you can bind the key combinations to run the command above.