Error: Line Magic Function `%Matplotlib` Not Found

Error: Line Magic Function `%Matplotlib` Not Found

I have just installed IPython on a Mac (MacOS 10.7.5) following the instructions for anaconda on , 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.

9 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.

5

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

0

if you run the notebook through shell, try the command

ipython notebook --pylab=inline
0

Maybe your code is wrong:
%matplotlib.inline

The correct one is:
%matplotlib inline

1

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.

1

If you run the notebook through shell, try the command

ipython notebook --pylab=inline 

It works for me.

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.

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]:

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.