Automatically update a figure in a loop

One thing I found out quickly is that I could not update a matplotlib plot in Python, at least automatically.  Then I found out this little trick.  The idea is that at the end of the loop one must put a [cci lang="python"]fig1.canvas.draw()[/cci] (obviously change the [cci lang="python"]fig1[/cci] part so that it reflects the variable name of the figure).  It works very well and seems to be quite quick for simple things.

[cc lang="python"]
fig1 = figure()

for ii in range(30):

## Clear the figure
clf()

# Do a plot that changes for each
# iteration
plot( range(ii) )

# Now set the xlimit so that it
# doesn’t change the plot
xlim((0,30))
ylim((0,30))

## Now the magic, we must update the
## canvas
fig1.canvas.draw()

[/cc]

Python, Scipy and Numpy

For approximately 16 years I have been using Matlab faithfully.  Back when I started (1993) all it had were 2D matrices and I remember having to use a package someone wrote up to have 3D volume capabilities (which are typically required for processing MRI datasets).  Matlab is great, don’t get me wrong.  There are few things that I don’t like about it.

So, sitting at a conference in Hawaii (tough life, I know) I had some ideas that I wanted to try out and quickly figured out that I could not get to the site license hosts back at my university.  Argh.  So, I started looking around to see if there were other options which would provide me a similar feel and processing capabilities.  There were a few options, but the one that stuck out was to use Python, Scipy and Numpy.  They were almost tailor made for what I wanted.

So, over the last little while I have been using the Python, Scipy, Numpy triad for most of my research and am feeling like I want to shift over completely the triad rather than using Matlab.