How to animate text in matplotlib?

被刻印的时光 ゝ 提交于 2019-12-07 16:07:07

问题


I am trying to animate a text box in a matplotlib figure, but cant seem to get it working. Anyone know how to do this properly?? An example is below.

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 = text(.5, .5, '', fontsize=15)


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

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

回答1:


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,


来源:https://stackoverflow.com/questions/18274137/how-to-animate-text-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!