.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_animation_simple_anim.py: ================== Animated line plot ================== .. image:: /gallery/animation/images/sphx_glr_simple_anim_001.png :class: sphx-glr-single-img .. code-block:: default import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation fig, ax = plt.subplots() x = np.arange(0, 2*np.pi, 0.01) line, = ax.plot(x, np.sin(x)) def init(): # only required for blitting to give a clean slate. line.set_ydata([np.nan] * len(x)) return line, def animate(i): line.set_ydata(np.sin(x + i / 100)) # update the data. return line, ani = animation.FuncAnimation( fig, animate, init_func=init, interval=2, blit=True, save_count=50) # To save the animation, use e.g. # # ani.save("movie.mp4") # # or # # from matplotlib.animation import FFMpegWriter # writer = FFMpegWriter(fps=15, metadata=dict(artist='Me'), bitrate=1800) # ani.save("movie.mp4", writer=writer) plt.show() .. _sphx_glr_download_gallery_animation_simple_anim.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: simple_anim.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: simple_anim.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_