On Sep 20, 2010, at 7:43 PM, Benjamin Root wrote: > On Mon, Sep 20, 2010 at 5:12 PM, Brian Blais <bbl...@bryant.edu> wrote:
> I am trying to do some simple calculations in a loop, and draw a plot > periodically within the loop, and the drawing is not updating. I'm using the > Enthought Python Distribution which is using Matplotlib 0.99.3 with python > 2.6.5 on Snow Leopard, OSX 10.6.4, and am running it in ipython with the > -pylab flag (and I've tried with the -wthread flag too). A sample piece of > code below. It is actually drawing, because when I control-C to stop, it > shows the plot. > > from pylab import * > from numpy import * > import sys > > def dot(): > sys.stdout.write('.') > sys.stdout.flush() > > def busy_loop(): > > for i in range(1000): > r=rand(100,100) > > return r > > for t in range(1000): > > r=busy_loop() > > clf() > imshow(r,interpolation='nearest',cmap=cm.gray) > draw() > show() > > dot() > > First, I would suggest using time.sleep() to do your busy loop: > > >>> import time > >>> time.sleep(0.1) > I tried that before (even upping to 1 second)...no dice. > > Second, you have the show() function within the loop. Call the show() > function only once (in interactive mode), and draw() can be used to update > the graph. also done...no effect. > Also note that some plotting functions return objects that have a function > like "update_data" that would allow you to modify the plot without having to > call clf(). sure, but that take more effort, and I don't really care about a slow down, because most of my time is spent in the busy loop. I do care about it displaying *at all*, which is the problem. I am familiar with the efficient way of animating, but for most things I want to focus on the computation and then display here and there, so I want the shortest, clearest plotting code without any optimizations. if I call plot commands, and then a draw, I expect it to actually pause right there until it is done drawing, and then continue...it's not doing that. another wrinkle: If I run ipython -pylab, and then run my script like: run do_my_script I get no plot showing (an empty figure window shows, with a busy process "rainbow spiral). Now, I control-C and the plots come up and my script stops. I then type again: run do_my_script it works! once the figure is drawn once, it seems to work just fine. the *first* time it doesn't display, and requires a control-C. weird! can anyone reproduce this? bb -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users