Matplotlib animate does not update placemark labels

I am trying to modify and example by starting an animation as x values ​​increase. I want to update the labels of the x-axis label to update according to the x values.

I am trying to use animation features (specifically FuncAnimation) in 1.2. I can set the xlimit, but the label tags are not updated. I have also tried to explicitly set the shortcut labels and that doesn't work.

I saw this: Animate matplotlib axes / ticks and I tried to set up bbox in animation.py but it didn't work. I'm new to matplotlib and don't know enough about what's really going on to solve this problem, so I would appreciate any help.

thank

"""
Matplotlib Animation Example

author: Jake Vanderplas
email: vanderplas@astro.washington.edu
website: http://jakevdp.github.com
license: BSD
Please feel free to use and modify this, but keep the above information. Thanks!
"""

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return line,

# animation function.  This is called sequentially
def animate(i):
    x = np.linspace(i, i+2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    ax.set_xlim(i, i+2)

    return line,

# call the animator.  blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
                           frames=200, interval=20, blit=True)

plt.show()

      

+3


source to share


1 answer


See Animating matplotlib axes / ticks , python matplotlib blit for axes or sides of a figure? , and Animated title in matplotlib

The simple answer is to delete blit=True



anim = animation.FuncAnimation(fig, animate, init_func=init,
                           frames=200, interval=20)

      

If you have blit = True

, only changed artists are redrawn (instead of re-painting all artists), which makes rendering more efficient. Artists are marked as modified if they return from the update function (in this case animate

). Another detail is that artists need to be in a bounding box with how the code works in animation.py

. See one of the links above to learn how to deal with this.

+5


source







All Articles