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

.. only:: html

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

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

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

.. _sphx_glr_gallery_userdemo_colormap_interactive_adjustment.py:


========================================
Interactive Adjustment of Colormap Range
========================================

Demonstration of how a colorbar can be used to interactively adjust the
range of colormapping on an image. To use the interactive feature, you must
be in either zoom mode (magnifying glass toolbar button) or
pan mode (4-way arrow toolbar button) and click inside the colorbar.

When zooming, the bounding box of the zoom region defines the new vmin and
vmax of the norm. Zooming using the right mouse button will expand the
vmin and vmax proportionally to the selected region, in the same manner that
one can zoom out on an axis. When panning, the vmin and vmax of the norm are
both shifted according to the direction of movement. The
Home/Back/Forward buttons can also be used to get back to a previous state.

.. GENERATED FROM PYTHON SOURCE LINES 18-32



.. image-sg:: /gallery/userdemo/images/sphx_glr_colormap_interactive_adjustment_001.png
   :alt: Pan on the colorbar to shift the color mapping Zoom on the colorbar to scale the color mapping
   :srcset: /gallery/userdemo/images/sphx_glr_colormap_interactive_adjustment_001.png, /gallery/userdemo/images/sphx_glr_colormap_interactive_adjustment_001_2_0x.png 2.0x
   :class: sphx-glr-single-img





.. code-block:: default

    import matplotlib.pyplot as plt
    import numpy as np

    t = np.linspace(0, 2 * np.pi, 1024)
    data2d = np.sin(t)[:, np.newaxis] * np.cos(t)[np.newaxis, :]

    fig, ax = plt.subplots()
    im = ax.imshow(data2d)
    ax.set_title('Pan on the colorbar to shift the color mapping\n'
                 'Zoom on the colorbar to scale the color mapping')

    fig.colorbar(im, ax=ax, label='Interactive colorbar')

    plt.show()


.. _sphx_glr_download_gallery_userdemo_colormap_interactive_adjustment.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: colormap_interactive_adjustment.py <colormap_interactive_adjustment.py>`



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

     :download:`Download Jupyter notebook: colormap_interactive_adjustment.ipynb <colormap_interactive_adjustment.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>`_
