dynamic image update

Can someone point me to the "best" way to dynamically update a 2D [image] array (think of cellular automata)? E.g., this simple example works, but gets sluggish after several iterations:

import numpy as N
import pylab as P

nx = 20
ny = 20
c = N.zeros(nx*ny, dtype='int8')
c.resize(ny,nx)

iters = 50
for its in range(iters):
   ix0 = N.random.rand()*nx
   iy0 = N.random.rand()*ny
   c[iy0,ix0] = 1
   P.imshow(c,interpolation='nearest')
   P.draw()

I'm guessing I'll want to use the mpl's API, but unsure of the best approach. I'm currently using mpl 0.98.5.

thanks, Randy

Use im.set_array rather than making multiple calls to imshow. See the
"dynamic_image*" examples at

http://matplotlib.sourceforge.net/examples/animation/index.html

···

On Tue, Jun 16, 2009 at 11:42 AM, Randy Heiland<heiland@...139...> wrote:

Can someone point me to the "best" way to dynamically update a 2D
[image] array (think of cellular automata)? E.g., this simple example
works, but gets sluggish after several iterations:

Is there a similar function (to im.set_array) for graph plots ?

- Sebastian

···

On Tue, Jun 16, 2009 at 6:54 PM, John Hunter<jdh2358@...287...> wrote:

On Tue, Jun 16, 2009 at 11:42 AM, Randy Heiland<heiland@...139...> wrote:

Can someone point me to the "best" way to dynamically update a 2D
[image] array (think of cellular automata)? E.g., this simple example
works, but gets sluggish after several iterations:

Use im.set_array rather than making multiple calls to imshow. See the
"dynamic_image*" examples at

http://matplotlib.sourceforge.net/examples/animation/index.html

On Tue, Jun 16, 2009 at 3:32 PM, Sebastian Haase<seb.haase@...287...>
wrote:> On Tue, Jun 16, 2009 at 6:54 PM, John

···

Hunter<jdh2358@...287...> wrote:

Is there a similar function (to im.set_array) for graph plots ?

for lines you would use line.set_data (or set_ydata, set_xdata). Eg

http://matplotlib.sourceforge.net/examples/animation/simple_anim_tkagg.html

JDH

Thanks for the quick answer.
This is obviously related to my post a few days ago -- a plotting benchmark ...
What are the restrictions for the functions
line.set_data
or
(assumingly similar) im.set_array ?
E.g. must the size (shape) of the data remain unchanged ?
Also, is there a performance difference if interactive mode is on or off ?

- Sebastian

···

On Tue, Jun 16, 2009 at 10:39 PM, John Hunter<jdh2358@...287...> wrote:

On Tue, Jun 16, 2009 at 3:32 PM, Sebastian Haase<seb.haase@...287...>
wrote:> On Tue, Jun 16, 2009 at 6:54 PM, John
Hunter<jdh2358@...287...> wrote:

Is there a similar function (to im.set_array) for graph plots ?

for lines you would use line.set_data (or set_ydata, set_xdata). Eg

http://matplotlib.sourceforge.net/examples/animation/simple_anim_tkagg.html