1

I am trying to animate a contour plot. The following example is close enough to what I want to achieve (from this archive):

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 2 * np.pi, 0.1)
X,Y = np.meshgrid(x,x)
f1 = np.sin(X) + np.sin(Y)
f2 = np.cos(X) + np.cos(Y)

plt.figure()
C = plt.contourf(f1)
plt.show()

for coll in C.collections:
    plt.gca().collections.remove(coll)

C = plt.contourf(f2)
plt.draw()

However, there seems to be an issue with the remove command and I'm not sure how to fix it.

1
  • What is the issue? What do you expect? What happens instead? Commented Aug 27, 2014 at 20:54

1 Answer 1

1

You might want to add

plt.pause(0.1)

after the remove command. This makes matplotlib actually draw the plot up to this point and wait 0.1 seconds so that you can see something happening, before it continues with the next iteration.

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

Comments

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.