python - 如何在 Matplotlib 中为文本设置动画?

标签 python matplotlib animation text

我正在尝试为 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)

最佳答案

文本是 artist并且您可以像任何其他动画一样对其进行动画处理 artist :

def updatefig(num):
    time_text.set_text(times[num])
    return time_text,

关于python - 如何在 Matplotlib 中为文本设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18274137/

相关文章:

python - 如何在 "Next"按钮之后使用 scrapy 获取 Amazon.com 链接?

python - matplotlib 仅显示一组 10 个图形中的一个,就像幻灯片一样

objective-c - 如何获取CABasicAnimation进度?

JavaFX 矩形不更新

python - 解析现有的配置文件

python - 如何保存 Keras 的训练历史以进行交叉验证(循环)?

python - Matplotlib Canvas 绘图

angular - 在运行时以 Angular 关闭动画

python - 使用 'try' 批量重命名 Pandas DF 列

python - Matplotlib tkagg 后端性能