.. 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 Click :ref:`here ` 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:: default 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 17.632 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-python :download:`Download Python source code: demo_func_animation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_func_animation.ipynb `