Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylab matplotlib "show" waits until window closes

I'd like to have the matplotlib "show" command return to the command line while displaying the plot. Most other plot packages, like R, do this. But pylab hangs until the plot window closes. For example:

import pylab
x = pylab.arange( 0, 10, 0.1)
y = pylab.sin(x)
pylab.plot(x,y, 'ro-')
pylab.show()   #  Python hangs here until the plot window is closed

I'd like to be able to view the plot while doing command line queries. I'm running Debian squeeze with python 2.6.6. My ~/.matplotlib/matplotlibrc contains

backend      : GTKAgg

Thanks!

like image 541
Sullivan Avatar asked Mar 17 '12 21:03

Sullivan


People also ask

Is PLT show () blocking?

Answer #6: plt. show() and plt. draw() are unnecessary and / or blocking in one way or the other.

Is PLT show () necessary?

Matplotlib is used in a IPython shell or a notebook (ex: Kaggle), plt. show() is unnecessary.

What is the difference between PyLab and Matplotlib?

PyLab is a procedural interface to the Matplotlib object-oriented plotting library. Matplotlib is the whole package; matplotlib. pyplot is a module in Matplotlib; and PyLab is a module that gets installed alongside Matplotlib. PyLab is a convenience module that bulk imports matplotlib.

What happens if I dont use %Matplotlib inline?

In the current versions of the IPython notebook and jupyter notebook, it is not necessary to use the %matplotlib inline function. As, whether you call matplotlib. pyplot. show() function or not, the graph output will be displayed in any case.


1 Answers

Add pylab.ion() (interactive mode) before the pylab.show() call. That will make the UI run in a separate thread and the call to show will return immediately.

like image 72
eudoxos Avatar answered Oct 12 '22 09:10

eudoxos