[IPython-User] %run and matplotlib event loop

Richard Everson R.M.Everson@exeter.ac...
Wed Jan 4 17:26:16 CST 2012

Thanks for IPython!  Making the (scientific computing) world a better place!

I was surprised to find that the run magic doesn't work with the (brilliant) matplotlib event loop magic.  Here's a minimal example, demo.py:

$ ipython --pylab
Python 2.7.2 (default, Sep  3 2011, 01:14:13) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Welcome to pylab, a matplotlib-based Python environment [backend: MacOSX].
For more information, type 'help(pylab)'.

In [1]: !cat demo.py

import numpy as np
import matplotlib.pyplot as plt


In [2]: run demo

No figure window appears, but plt.show() (or plain show()) causes the plot to be displayed.  Interestingly, "run demo" and show() a second time doesn't display the updated plot unless the figure has been closed or beforehand.   

On the other hand, just importing demo displays the plot as I expected, and reload(demo) displays it again.  This is all with IPython 0.12 using the MacOSX matplotlib (1.1.0) backend.  I thought that earlier versions of IPython %run would immediately display matplotlib figures?  I haven't got an old version around to test, but (a) am I just missing something that would allow this or (b) is it the desired behaviour or a bug?  From my point of view it would be very helpful for %run to utilise the matplotlib event loop magic.


More information about the IPython-User mailing list