I have a NxN grid with some values, which change every time step. I have found a way to plot a single grid configuration of this with matshow function, but I don't know how do I update the status with every time step. Here is a simple example:

This produces 10 pictures. I'd like to animate this instead producing individual pictures, and for example I'd like to choose a time step between changes (that is, frame rate).
Also, I'm open to suggestions for a different functions, if matshow is not the way to go, but please keep it simple, I'm relatively inexperienced.

I should have asked this in the question, but is there a way to put an condition on a-b so that animation stops, and only the last figure stays (as if I did static plot). For example if max(a-b)>22?
–
enedeneMay 3 '12 at 14:59

1

@bmu I took the liberty of adding a few frames of your "movie" as a animated gif - great answer! Looking at the animation, I would suggest that the colorbar has fixed limits so it doesn't change during the animation.
–
HookedMay 3 '12 at 15:01

@Hooked: I tried to upload an animated gif, but something went wrong, so I thought Stackoverflow do not allow it. But it works, nice.
–
bmuMay 3 '12 at 15:11

@enedene: You can stop the animation for a certain time with time.sleep() if a condition is met. However I think it would be difficult to interact with the user if he wants to continue.
–
bmuMay 3 '12 at 15:46

The easiest way is probably to have matplotlib save individual images and then have another program or library stitch together them to an animation. This approach uses a module called write2gif but you can also use mencoder, ffmpeg or any other software capable of producing video:

Thank you for your answer. There are examples of animating plots within matplotlib interface, for example: scipy.org/Cookbook/Matplotlib/Animations Is there no way for my example to be animated within that interface as well?
–
enedeneMay 3 '12 at 11:29