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

.. only:: html

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

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

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

.. _sphx_glr_auto_examples_quickflat_plot_make_gif.py:


====================================
Animate a series of volumes as a GIF
====================================

A convenient way to compare two flat maps (e.g., prediction performance or
tuning weights) is to flip back and forth between them. This example shows how
to make an animated gif in which each frame is a flatmap.

.. GENERATED FROM PYTHON SOURCE LINES 11-16

.. code-block:: Python

    import cortex
    import matplotlib.pyplot as plt
    import numpy as np
    np.random.seed(1234)








.. GENERATED FROM PYTHON SOURCE LINES 17-19

Create several pycortex Volumes


.. GENERATED FROM PYTHON SOURCE LINES 19-23

.. code-block:: Python


    volumes = {'first': cortex.Volume.random(subject='S1', xfmname='fullhead', vmin=-2, vmax=2, cmap="RdBu_r"),
               'second': cortex.Volume.random(subject='S1', xfmname='fullhead', vmin=-2, vmax=2, cmap="RdBu_r")}








.. GENERATED FROM PYTHON SOURCE LINES 24-26

Plot flat maps individually


.. GENERATED FROM PYTHON SOURCE LINES 26-32

.. code-block:: Python


    _ = cortex.quickflat.make_figure(volumes['first'], colorbar_location="right")
    _ = cortex.quickflat.make_figure(volumes['second'], colorbar_location="right")
    _ = plt.show()





.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /auto_examples/quickflat/images/sphx_glr_plot_make_gif_001.png
         :alt: plot make gif
         :srcset: /auto_examples/quickflat/images/sphx_glr_plot_make_gif_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/quickflat/images/sphx_glr_plot_make_gif_002.png
         :alt: plot make gif
         :srcset: /auto_examples/quickflat/images/sphx_glr_plot_make_gif_002.png
         :class: sphx-glr-multi-img


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

 .. code-block:: none

    ** (inkscape:4787): WARNING **: 21:54:37.749: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function.
    ** (inkscape:4800): WARNING **: 21:54:38.657: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function.




.. GENERATED FROM PYTHON SOURCE LINES 33-35

Generate an animated gif that switches between frames every 1.5 seconds


.. GENERATED FROM PYTHON SOURCE LINES 35-39

.. code-block:: Python


    filename = "./flatmap_comparison.gif"
    cortex.quickflat.make_gif(filename, volumes, frame_duration=1.5, colorbar_location="right")





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

 .. code-block:: none

    ** (inkscape:4813): WARNING **: 21:54:40.871: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function.
    ** (inkscape:4827): WARNING **: 21:54:42.142: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function.




.. GENERATED FROM PYTHON SOURCE LINES 40-42

Display gif inline in an IPython notebook


.. GENERATED FROM PYTHON SOURCE LINES 42-52

.. code-block:: Python


    import io
    from IPython.display import Image

    stream = io.BytesIO()
    cortex.quickflat.make_gif(stream, volumes, frame_duration=1.5, colorbar_location="right")

    Image(stream.read())






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

 .. code-block:: none

    ** (inkscape:4841): WARNING **: 21:54:43.979: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function.
    ** (inkscape:4854): WARNING **: 21:54:45.325: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function.

    <IPython.core.display.Image object>



.. GENERATED FROM PYTHON SOURCE LINES 53-54

.. image:: ../../flatmap_comparison.gif


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

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


.. _sphx_glr_download_auto_examples_quickflat_plot_make_gif.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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