views:

58

answers:

1

I have a loop that is adding a line to a plot on each iteration. Right now this is horribly slow as it seems to redraw the the whole graph each time. Is it possible to disable screen updates for a graph while it is being set up then re-enable them afterwards.

Here's the code:

    for rr,dd in zip(angles,dists):
        if dd == inf:
            pass
        else:
            lineend = (array([cos(rr), sin(rr)]) * dd)+origin;
            plot([origin[0], lineend[0]], [origin[1], lineend[1]],'-b');

I know I should just combine this all into one call to plot and I'll probably do it for this example. But there are other bits where that would be more of a problem so a general solution would be really helpful.

Thanks!

+2  A: 

It sounds like you have the interactive mode on, so you should just set it to off using the command

ioff()

Note that when interactive mode is off, you'll need to use the command show() to display the plots.

tom10
Wow, that's an incredible difference! Thanks!
Thomas Parslow
I'm glad to hear it worked for you. I think that cases like this are exactly why a non-interactive mode exists.
tom10