I tried using matplotlib's ArtistAnimation. The text and titles of the figure are supposed to change in each frame, but they don't. I have read tons of posts on similar problems, but I still don't understand what is the solution. The demos don't show updating titles as far as I could find.
If anybody out there knows, I would be grateful!
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
fig =plt.figure()
ims=[]
for iternum in range(4):
plt.title(iternum)
plt.text(iternum,iternum,iternum)
ims.append([plt.scatter(np.random.randint(0,10,5), np.random.randint(0,20,5),marker='+' )])
#plt.cla()
ani = animation.ArtistAnimation(fig, ims, interval=500, blit=False,
repeat_delay=2000)
plt.show()
You need to supply the artists to animate as a list of sequences to the
ArtistAnimation
. In the code from the question you only supply the scatter, but not the text and title.Unfortunately the title is also part of the axes and thus will not change even if supplied. So you may use a normal text instead.
You may consider using
FuncAnimation
instead ofArtistAnimation
. This would allow to change the title easily.To animate artists, you have to return a reference to each artists in your
ims[]
array, including theText
objects.However it doesn't work for the title, I don't know why. Maybe somebody with a better understanding of the mechanisms involved will be able to enlighten us.
Nevertheless, the title is just a
Text
object, so we can produce the desired effect using: