views:

254

answers:

3

Hi All

I am using matplotlib to draw charts and graphs.

When I plot the chart using the command show() my code blocks at this command.

I would like to refresh my list of values with new data , and than refresh the image on the background. How to do that without closing each time the window with the graph? Below is the code I am using

Thanks

AFG

import pylab
a = (1,2,3,4)
pylab.plot(a)
pylab.show() # blocks here
A: 

This works by invoking Ipython with the -wthread (or the -pylab) option. It will not block on show anymore.

Olivier
Hi! Thanks for the response. I didn't know about IPython and I am using the DOS shell. I will switch to this IPython and let's see if it improves. Thanks anyway!
Abruzzo Forte e Gentile
+1  A: 

If you are not using the IPython shell but instead running a program, you probably want to do:

pyplot.draw()

after a plot(), possibly followed by

raw_input("Press enter when done...")

As far as I understand, the draw() call is automatically done if you do pyplot.ion() at the beginning of your program (however, this does not appear to work with all plotting backends on all platforms).

pyplot.show() is actually an infinite loop that handles events in the main plotting window (such as zooming, panning, etc.).

EOL
+1  A: 

In IPython started with -pylab it should not block.

Otherwise: With ion() you turn the interactive mode on. show() does not block your system anymore. Every draw() or plot(x, y) updated your plot.

ioff() turns interactive mode off. Useful if you add lots of data and don't want to update every little detail.

See also: http://www.scipy.org/Cookbook/Matplotlib/Animations

Stefan