3

I'd like to make an animation with matplotlib.animation that dynamically updates text and title assigned to axes in each frame.

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()

The output contains cluttered titles and texts when displaying the animation. Is there any way to do that?

I'd appreciate any comment of help.

Ehsan M. Kermani
  • 912
  • 2
  • 12
  • 26

0 Answers0