我想用matplotlib.animation制作一个动画,动态更新分配给每个帧中轴的文本和标题。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax = plt.axes()
def func(year):
# do something
return data # a 1d numpy array for example
def plot_data(year):
d = func(year)
ax.set_title(year)
ax.text(1, 2, year)
return ax.bar(np.array([1,2]), d) # bar plot
bars = []
for year in years:
bars.append(plot_data(year))
anim = animation.ArtistAnimation(fig, bars)
plt.show()
显示动画时,输出包含杂乱的标题和文本。有没有办法做到这一点?
我很感激任何帮助评论。