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>
matplotlib.get_backend() shows that I have the
%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.
Read more… Read less…
%pylab inline magic command.
To make matplotlib inline by default in Jupyter (IPython 3):
c.InteractiveShellApp.matplotlib = 'inline'
Please note that adding this line to
ipython_notebook_config.py would not work.
Otherwise it works well with Jupyter and IPython 3.1.0
I have to agree with foobarbecue (I don't have enough recs to be able to simply insert a comment under his post):
It's now recommended that python notebook isn't started wit the argument
--pylab, and according to Fernando Perez (creator of ipythonnb)
%matplotlib inline should be the initial notebook command.