.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_02_compute.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_gallery_plot_02_compute.py: .. _compute_exemple: Animation using computed data ############################# explain the utilisation of the ``compute`` function .. GENERATED FROM PYTHON SOURCE LINES 11-48 .. video:: /home/docs/checkouts/readthedocs.org/user_builds/animation-maker/checkouts/latest/doc/source/gallery/images/sphx_glr_plot_02_compute_001.mp4 :autoplay: :loop: .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import xarray as xr ANIM_FPS = 20 ANIM_OUTPUT_FOLDER = "animation/example_02" ANIM_MAX_FRAMES = ANIM_FPS * 4 size = 10 fps = 10 max_frames = fps * 8 def compute(): x = np.zeros(size) + np.nan y = np.zeros(size) + np.nan for i in range(max_frames): n = i / size * np.pi x[:-1] = x[1:] y[:-1] = y[1:] x[-1] = np.sin(n) * 0.9 y[-1] = np.cos(n) * 0.9 yield xr.Dataset({"x": ("size", np.copy(x)), "y": ("size", np.copy(y))}) def plot(i, ds): fig, ax = plt.subplots(1, 1, figsize=(4, 4), dpi=120) ax.set_xlim(-1, 1) ax.set_ylim(-1, 1) size = ds.sizes["size"] ax.scatter(ds.x, ds.y, s=np.arange(size) * 70, alpha=np.arange(size) / size) return fig .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.288 seconds) .. _sphx_glr_download_gallery_plot_02_compute.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_compute.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_compute.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_compute.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_