
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/animation/simple_scatter.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_animation_simple_scatter.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_animation_simple_scatter.py:


=============================
Animated scatter saved as GIF
=============================

Output generated via `matplotlib.animation.Animation.to_jshtml`.

.. GENERATED FROM PYTHON SOURCE LINES 8-35

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    import matplotlib.animation as animation

    fig, ax = plt.subplots()
    ax.set_xlim([0, 10])

    scat = ax.scatter(1, 0)
    x = np.linspace(0, 10)


    def animate(i):
        scat.set_offsets((x[i], 0))
        return (scat,)


    ani = animation.FuncAnimation(fig, animate, repeat=True, frames=len(x) - 1, interval=50)

    # To save the animation using Pillow as a gif
    # writer = animation.PillowWriter(fps=15,
    #                                 metadata=dict(artist='Me'),
    #                                 bitrate=1800)
    # ani.save('scatter.gif', writer=writer)

    plt.show()




.. image-sg:: /gallery/animation/images/sphx_glr_simple_scatter_001.png
   :alt: simple scatter
   :srcset: /gallery/animation/images/sphx_glr_simple_scatter_001.png, /gallery/animation/images/sphx_glr_simple_scatter_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 36-41

.. tags::
   component: animation,
   plot-type: scatter,
   purpose: reference,
   level: intermediate


.. _sphx_glr_download_gallery_animation_simple_scatter.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

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

    .. container:: sphx-glr-download sphx-glr-download-python

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: simple_scatter.zip <simple_scatter.zip>`


.. only:: html

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

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