ERROR: Line magic function `%matplotlib` not found

Question:

I have just installed IPython on a Mac (MacOS 10.7.5) following the instructions for anaconda on http://ipython.org/install.html, with no obvious errors. I now want to work my way through the example notebooks. In notebook "Part 1 – Running Code", everything works as it should until I get to

%matplotlib inline

Then I get the error message

ERROR: Line magic function %matplotlib not found.

Everything after that works, except that plots, instead of appearing inline, pop up in a new window.

Asked By: Leon Avery

||

Answers:

Try:

import IPython
print(IPython.sys_info())

Does it report that you are on 'ipython_version' 1.0+?
You might be picking up an older version of IPython that do not have the %matplotlib magic.

Answered By: Matt

I had this problem on Windows, but I believe it will work the same way:

  1. Get rid of the old IPython. The command is conda remove ipython.
  2. Get easy_install if you don’t have it. Follow the instructions to install easy_install for your system.
  3. Use easy_install to reinstall the newest IPython. The command is easy_install ipython[all], just like it shows on the site.

With Conda’s default IPython gone, it should indicate it’s loading IPython 1.0.0. You can make sure by running either IPython or the IPython Notebook and running the command %lsmagic. If matplotlib is in the list, you’ve got it.

Answered By: GeoffB

If you have Anaconda, just do conda update ipython from the command line. No need for removal, easy_install and all the rest.

Answered By: Roger

if you run the notebook through shell, try the command

ipython notebook --pylab=inline
Answered By: irenemeanspeace

Make sure, you use the right installation of ipython

In my case, I have system-wide Python installation for application development and beside that, also anaconda for data analysis (to be used with ipython notebooks).

When starting ipython notebook, I shall set PATH properly to use anaconda version of ipython.

Forgetting to set PATH, I use system-wide installed ipython which does not serve running notebooks well resulting in the complain about %matplotlib inline as noted in OP.

When I set PATH properly and used anaconda version of python and ipython, all goes well.

Answered By: Jan Vlcinsky

If you run the notebook through shell, try the command

ipython notebook --pylab=inline 

It works for me.

Answered By: jiangzuomei

instead of the inline command, I simply put this after the plot
matplotlib.pyplot.show()

Answered By: gandhar_nigudkar

I had a similar problem on windows.
Make sure that you’ve added Conda and python to the path. To check that you can run the following command on command prompt

jupyter notebook

if it doesnt recognize then go to anaconda prompt and type

where conda
where python

refer the image for paths to include
[1]: https://i.stack.imgur.com/QeA5d.png

Add these to the path and mostly youll be good to go

Answered By: tanvi

Maybe your code is wrong:
%matplotlib.inline

The correct one is:
%matplotlib inline

Answered By: Arjun M S

Try updating pip3, (if you are using) conda, etc. and use Jupyterlab instead of Jupyter Notebook (as it has a lot more features).
%matplotlib inline works in the IPython Console here.
How to open Console in JupyterLab
Sample Code using %matplotlib inline

Answered By: Wood