You can clone with
If I use the notebook not in pylab mode (ipython notebook), I can see a Matplotlib figure only once. When I run the code the first time (eg by clicking 'run all'), the figure appears in a new window as normal. But when I close the figure and later want to see it again, I don't get it anymore. Running the code a second or more time does not display the figure anymore.
Even when I close the notebook and open it again, the figure does not display.
When I use the notebook in pylab mode (ipython notebook --pylab), I don't have that problem (running the code = display the figure each time).
I think you have to enable pylab integration at the command-line. Running matplotlib with a GUI backend without pylab integration in the IPython kernel is not reliable, because the default kernel will not pump the inputhook/eventloop that the GUI toolkits typically need.
OK, but running matplotlib with a GUI backend without pylab does work in the IPython console and Qt console, only not in the notebook.
And I think you should be able to use matplotlib in the notebook, also without using pylab.
It's strange that the qtconsole and notebook would behave differently, since they use the exact same kernel code.
I should specify that you don't have to use pylab-mode, but you should at least inform IPython about the GUI eventloop you will be using (e.g. ipython notebook --gui=qt). It just isn't reasonable to have multiple eventloops play well together unless one knows about the other. And the kernel's knowledge of which eventloop to work with is established at launch time (it determines which Kernel subclass to use).
ipython notebook --gui=qt
That said, when matplotlib is not interactive, you have to mess around with show(), and closing windows, etc. to get back and forth between the plot windows being responsive and the ability to run new code.
Ah, it looks like the kernel doesn't actually support setting just the GUI at this point, but it should.
How well does the qtconsole work without specifying pylab-mode, and what backend are you using? Can you describe exactly how the qtconsole and notebook differ in behavior with a specific code sample?
This is the code snippet I used:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)
y = np.array([5,6,8,4,7,2,5,9,8,5])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y, '-o')
So the behaviour in the different cases:
Notebook with pylab enabled (starting from the terminal with command ipython notebook --pylab):
ipython notebook --pylab
Notebook without pylab (starting from the terminal with command ipython notebook):
Close the window, re-run the code, the figure does not appear again.
This is rather frustrating, because you cannot see a figure again after you have closed it, even not if you change the code a little bit to adjust the figure.
In the Qt console (with and without pylab) it also behaves normal. If you run the code snippet, the figure window appears. Close it, arrow up to get the same code and run it again: the figure window appears again.
Matplotlib uses the default backend TkAgg (and I am using Ubuntu).
After testing, I should note that I don't see different behavior between the qtconsole and the notebook.
I do see the same behavior you do when I use TkAgg (not shown the second time), but not if I use other backends (qt4, osx).
Qt4Agg, TkAgg tested on Ubuntu 10.04, Python 2.6.5, matplotlib 0.99.1.1
OSX on 10.7, Python 2.7.1, matplotlib 1.1dev
I should also note that I also the exact same issue in a plain Python script: calls to show() after the first do not result in a display when using TkAgg, so IPython without pylab integration is behaving exactly like regular Python, as it should be.
I do not see this issue using TkAgg with matplotlib master on OSX, so it may be fixed in master, or it may not affect TkAgg on OSX.
Closing, as the behavior appears to be general to Python+matplotlib 0.99 + TkAgg (may not even affect 1.1), and does not appear to have anything to do with IPython.
I want to stress that there was definitely a difference, I tested it again and the difference was between the plain python and ipython console on the one hand, and the ipython qtconsole and notebook on the other hand.
But after upgrading both ipython (I don't know if the 0.12dev has changed) and matplotlib (1.0.1), all problems are solved. It behaves normal in all cases. So issue closed!