.. _sphx_glr_gallery_animation_random_data.py: =========== Random data =========== An animation of random data. .. image:: /gallery/animation/images/sphx_glr_random_data_001.png :align: center .. code-block:: python import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Fixing random state for reproducibility np.random.seed(19680801) fig, ax = plt.subplots() line, = ax.plot(np.random.rand(10)) ax.set_ylim(0, 1) def update(data): line.set_ydata(data) return line, def data_gen(): while True: yield np.random.rand(10) ani = animation.FuncAnimation(fig, update, data_gen, interval=100) plt.show() **Total running time of the script:** ( 0 minutes 0.017 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: random_data.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: random_data.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_