.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\matplotlib\demo_func_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_python_packages_matplotlib_demo_func_animation.py: Function animation ===================== .. GENERATED FROM PYTHON SOURCE LINES 5-36 .. container:: sphx-glr-animation .. raw:: html
.. code-block:: Python import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation fig, ax = plt.subplots() xdata, ydata = [], [] (ln,) = plt.plot([], [], "ro", animated=True) 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() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.716 seconds) .. _sphx_glr_download_11_demos_python_packages_matplotlib_demo_func_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_func_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_func_animation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_func_animation.zip `