[Matplotlib-users] Animation not working

Peter John.V. peterjv26 at googlemail.com
Sat Sep 25 13:34:08 EDT 2021


Hi, I am new to matplotlib and was playing around with it and trying to do
some simple animation. I watched some tutorial videos from youtube and
tried below code which is a cut/paste of the animation example code from
matplotlib official documentation.
 I tried to run this in Spyder 4.1.5. But I just get a blank figure and no
animation.
I tried to copy different example code blocks from different tutorials and
they just give the initial figure and no animation. Is there some
configuration setting to be done for animation to work? Or anything else I
am missing? Please help. TIA

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

fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')

def init():
    ax.set_xlim(0, 2*np.pi)
    ax.set_ylim(-1, 1)
    return ln,

def update(frame):
    xdata.append(frame)
    ydata.append(np.sin(frame))
    ln.set_data(xdata, ydata)
    return ln,

ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
                    init_func=init, blit=True)
plt.show()

Regards
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/matplotlib-users/attachments/20210925/6e3a4817/attachment.html>


More information about the Matplotlib-users mailing list