Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate text in Matplotlib?

I am trying to animate a text box in a Matplotlib figure, but can't seem to get it working. Does 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 = 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)
like image 474
Dave Avatar asked Aug 16 '13 13:08

Dave


People also ask

How do you make text appear animation?

On the slide, select the box that contains your text. On the Animations tab, select the Add Animation drop-down menu, and select an animation, such as Appear, Fade In, or Fly In. Select the Animations tab, and then select Animation Pane.

Can you animate Matplotlib?

Animations in Matplotlib can be made by using the Animation class in two ways: By calling a function over and over: It uses a predefined function which when ran again and again creates an animation. By using fixed objects: Some animated artistic objects when combined with others yield an animation scene.

Can text and graphics be animated?

As you can see, text can be animated in a variety of ways by using different animation effects and transition styles.


1 Answers

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,
like image 67
tacaswell Avatar answered Sep 30 '22 13:09

tacaswell