You have also to add the text object to the list of artists for each frame:
import matplotlib.animation as animation
from PIL import Image
from IPython.display import HTML
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ims = []
for i in range(10):
artists = ax.plot(np.random.rand(10), np.random.rand(10))
text = ax.text(x=0.5, y=0.5, s=i)
artists.append(text)
ims.append(artists)
ani = animation.ArtistAnimation(fig, ims, interval=200)
HTML(ani.to_jshtml())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…