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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_tutorial_03_figures_d_gif.py>`
        to download the full example code. or to run this example in your browser via Binder

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

.. _sphx_glr_tutorial_03_figures_d_gif.py:


.. _gif_movie_example:

Create a GIF Movie
~~~~~~~~~~~~~~~~~~
Generate a moving gif from an active plotter.

.. note::
   Use ``lighting=False`` to reduce the size of the color space to avoid
   "jittery" GIFs, especially for the scalar bar.

.. GENERATED FROM PYTHON SOURCE LINES 13-56

.. code-block:: Python


    import numpy as np
    import pyvista as pv

    x = np.arange(-10, 10, 0.5)
    y = np.arange(-10, 10, 0.5)
    x, y = np.meshgrid(x, y)
    r = np.sqrt(x**2 + y**2)
    z = np.sin(r)

    # Create and structured surface
    grid = pv.StructuredGrid(x, y, z)

    # Create a plotter object and set the scalars to the Z height
    plotter = pv.Plotter(notebook=False, off_screen=True)
    plotter.add_mesh(
        grid,
        scalars=z.ravel(),
        lighting=False,
        show_edges=True,
        scalar_bar_args={"title": "Height"},
        clim=[-1, 1],
    )

    # Open a gif
    plotter.open_gif("wave.gif")

    pts = grid.points.copy()

    # Update Z and write a frame for each updated position
    nframe = 15
    for phase in np.linspace(0, 2 * np.pi, nframe + 1)[:nframe]:
        z = np.sin(r + phase)
        pts[:, -1] = z.ravel()
        grid.points = pts
        plotter.update_scalars(z.ravel(), render=False)

        # Write a frame. This triggers a render.
        plotter.write_frame()

    # Closes and finalizes movie
    plotter.close()





.. image-sg:: /tutorial/03_figures/images/sphx_glr_d_gif_001.gif
   :alt: d gif
   :srcset: /tutorial/03_figures/images/sphx_glr_d_gif_001.gif
   :class: sphx-glr-single-img




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/pyvista/plotting/plotter.py:4989: PyVistaDeprecationWarning: This method is deprecated and will be removed in a future version of PyVista. Directly modify the scalars of a mesh in-place instead.
      warnings.warn(




.. GENERATED FROM PYTHON SOURCE LINES 57-64

.. raw:: html

    <center>
      <a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/03_figures/d_gif.ipynb">
        <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/ width="150px">
      </a>
    </center>


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 2.064 seconds)


.. _sphx_glr_download_tutorial_03_figures_d_gif.py:

.. only:: html

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

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/03_figures/d_gif.ipynb
        :alt: Launch binder
        :width: 150 px

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

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

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

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

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

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


.. only:: html

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

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