Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make IPython notebook matplotlib plot inline

I am trying to use IPython notebook on MacOS X with Python 2.7.2 and IPython 1.1.0.

I cannot get matplotlib graphics to show up inline.

import matplotlib import numpy as np import matplotlib.pyplot as plt %matplotlib inline   

I have also tried %pylab inline and the ipython command line arguments --pylab=inline but this makes no difference.

x = np.linspace(0, 3*np.pi, 500) plt.plot(x, np.sin(x**2)) plt.title('A simple chirp') plt.show() 

Instead of inline graphics, I get this:

<matplotlib.figure.Figure at 0x110b9c450> 

And matplotlib.get_backend() shows that I have the 'module://IPython.kernel.zmq.pylab.backend_inline' backend.

like image 891
Ian Fiske Avatar asked Oct 16 '13 17:10

Ian Fiske


People also ask

How do you make an inline plot on a Jupyter notebook?

You can use the magic function %matplotlib inline to enable the inline plotting, where the plots/graphs will be displayed just below the cell where your plotting commands are written. It provides interactivity with the backend in the frontends like the jupyter notebook.

What is the use of matplotlib inline in Jupyter notebook?

%matplotlib inline sets the backend of matplotlib to the 'inline' backend: With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.

Do We Still Need %Matplotlib inline?

So %matplotlib inline is only necessary to register this function so that it displays in the output. Running import matplotlib. pyplot as plt also registers this same function, so as of now it's not necessary to even use %matplotlib inline if you use pyplot or a library that imports pyplot like pandas or seaborn.


1 Answers

I used %matplotlib inline in the first cell of the notebook and it works. I think you should try:

%matplotlib inline  import matplotlib import numpy as np import matplotlib.pyplot as plt 

You can also always start all your IPython kernels in inline mode by default by setting the following config options in your config files:

c.IPKernelApp.matplotlib=<CaselessStrEnum>   Default: None   Choices: ['auto', 'gtk', 'gtk3', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']   Configure matplotlib for interactive use with the default matplotlib backend. 
like image 63
eNord9 Avatar answered Oct 08 '22 08:10

eNord9