2

In the past I was able to do simple animations with matplotlib with a for loop, but this hasn't worked for some time now.

The standard answer is that you have to turn interactive mode on and/or force a redraw with matplotlib.pyplot.draw(). Here is my minimal working example:

import numpy as np
import matplotlib

matplotlib.use('Qt4Agg')

import matplotlib.pyplot as mplot

mplot.ion()

fig = mplot.figure(1)
ax = fig.add_subplot(111)

for ii in np.arange(0,10):
    x = 200*np.random.rand(30)
    ax.plot(x)
    mplot.draw()
    filename = ("img_%d.png" % ii)
    mplot.savefig(filename)

When I run this in Interactive Python Editor, I get one figure at the very end with all the plots in it (this also happens with mplot.show())

When I run this in IPython 3.1 (with Python 3.3.5) from the command line, I get nothing at all.

The mplot.savefig(filename) line does seem to work, as the images are generated.

(It's possible this is a bug in the Qt4 backend.)

1 Answer 1

2

Try deleting the line matplotlib.use('Qt4Agg'). Works for me. Also works with matplotlib.use('TkAgg'). So it is a backend problem. There is another way to do animations.

Sign up to request clarification or add additional context in comments.

1 Comment

So you tried it with matplotlib.use('Qt4Agg') and it didn't work for you either?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.