I've installed iPython + SciPy Superpack on a Mac (OSX Lion).
If I plot using matplotlib.pyplot, it will pop up a window with the graph, and I close this for the ipython kernel to continue.
from matplotlib import pyplot as plt
plt.plot([1, 2, 3], [3, 6, 9])
plt.show()
However, If I try the inline (starting with --pylab inline
or --pylab=inline
) and import pylab, instead of a plot inside the notebook (which I expect), I get an external window, which never renders anything.
Still in an external window:
import pylab
pylab.plot([1, 2, 3], [3, 6, 9])
pylab.show()
Since I've started the notebook with ipython notebook --pylab=inline
it should already be so, but if I use %pylab inline
in a cell and run it, I get the help, and the same code above creates a blank window, and hangs the kernel - I can only force kill the window.
How should this work?
The only reason %matplotlib inline is used is to render any matplotlib diagrams even if the plt. show() function is not called. However, even if %matplotlib inline is not used, Jupyter will still display the Matplotlib diagram as an object, with something like matplotlib. lines.
The line magic command %matplotlib inline enables the drawing of matplotlib figures in the IPython environment. Once this command is executed in any cell, then for the rest of the session, the matplotlib plots will appear directly below the cell in which the plot function was called.
%matplotlib notebook will lead to interactive plots embedded within the notebook. %matplotlib inline will lead to static images of your plot embedded in the notebook.
Okay - the problem was that the original ipython notebook process was still running (I'd not killed it) and the new one with the inline flag was running on a different port.
If you are having this issue - first save all your notebooks, then check you haven't got other processes running and kill any that shouldn't be running.
If you want to avoid this confusion, you can set NotebookApp.port_retries=0
in your configuration, in which case later notebook calls will give up, rather than listen on a new port. (Credit to minrk, in comments)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With