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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_images_contours_and_fields_multi_image.py>`
        to download the full example code

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

.. _sphx_glr_gallery_images_contours_and_fields_multi_image.py:


===========
Multi Image
===========

Make a set of images with a single colormap, norm, and colorbar.

.. GENERATED FROM PYTHON SOURCE LINES 8-54

.. code-block:: default


    from matplotlib import colors
    import matplotlib.pyplot as plt
    import numpy as np

    np.random.seed(19680801)
    Nr = 3
    Nc = 2

    fig, axs = plt.subplots(Nr, Nc)
    fig.suptitle('Multiple images')

    images = []
    for i in range(Nr):
        for j in range(Nc):
            # Generate data with a range that varies from one plot to the next.
            data = ((1 + i + j) / 10) * np.random.rand(10, 20)
            images.append(axs[i, j].imshow(data))
            axs[i, j].label_outer()

    # Find the min and max of all colors for use in setting the color scale.
    vmin = min(image.get_array().min() for image in images)
    vmax = max(image.get_array().max() for image in images)
    norm = colors.Normalize(vmin=vmin, vmax=vmax)
    for im in images:
        im.set_norm(norm)

    fig.colorbar(images[0], ax=axs, orientation='horizontal', fraction=.1)


    # Make images respond to changes in the norm of other images (e.g. via the
    # "edit axis, curves and images parameters" GUI on Qt), but be careful not to
    # recurse infinitely!
    def update(changed_image):
        for im in images:
            if (changed_image.get_cmap() != im.get_cmap()
                    or changed_image.get_clim() != im.get_clim()):
                im.set_cmap(changed_image.get_cmap())
                im.set_clim(changed_image.get_clim())


    for im in images:
        im.callbacksSM.connect('changed', update)

    plt.show()




.. image:: /gallery/images_contours_and_fields/images/sphx_glr_multi_image_001.png
    :alt: Multiple images
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 55-62

------------

References
""""""""""

The use of the following functions, methods and classes is shown
in this example:

.. GENERATED FROM PYTHON SOURCE LINES 63-74

.. code-block:: default


    import matplotlib
    matplotlib.axes.Axes.imshow
    matplotlib.pyplot.imshow
    matplotlib.figure.Figure.colorbar
    matplotlib.pyplot.colorbar
    matplotlib.colors.Normalize
    matplotlib.cm.ScalarMappable.set_cmap
    matplotlib.cm.ScalarMappable.set_norm
    matplotlib.cm.ScalarMappable.set_clim
    matplotlib.cbook.CallbackRegistry.connect




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

 Out:

 .. code-block:: none


    <function CallbackRegistry.connect at 0x7f73c161cee0>




.. _sphx_glr_download_gallery_images_contours_and_fields_multi_image.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
