9

我正在尝试为 Matplotlib 图中的文本框设置动画,但似乎无法使其正常工作。有谁知道如何正确地做到这一点?下面是一个例子。

from matplotlib import animation
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap

fig = plt.figure()
ax = fig.add_subplot(111)

times = ['first', 'second', 'third']

time_text = ax.text(.5, .5, '', fontsize=15)


def updatefig(num):
    global mt
    mt = ax.text(.5, .5, times[num], fontsize=15)

anim = animation.FuncAnimation(fig, updatefig, frames=len(times)-1, blit=True, init_func=init)
4

1 回答 1

19

Text is an artist and you animate it exactly like any other artist:

def updatefig(num):
    time_text.set_text(times[num])
    return time_text,
于 2013-08-16T16:26:05.047 回答