

.. _sphx_glr_gallery_animation_simple_anim.py:


===========
Simple Anim
===========

A simple example of an animated plot




.. image:: /gallery/animation/images/sphx_glr_simple_anim_001.png
    :align: center





.. code-block:: python

    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 animate(i):
        line.set_ydata(np.sin(x + i/10.0))  # update the data
        return line,


    # Init only required for blitting to give a clean slate.
    def init():
        line.set_ydata(np.ma.array(x, mask=True))
        return line,

    ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
                                  interval=25, blit=True)
    plt.show()

**Total running time of the script:** ( 0 minutes  0.108 seconds)



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: simple_anim.py <simple_anim.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: simple_anim.ipynb <simple_anim.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
