.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/images_contours_and_fields/colormap_interactive_adjustment.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_images_contours_and_fields_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. .. redirect-from:: /gallery/userdemo/colormap_interactive_adjustment .. GENERATED FROM PYTHON SOURCE LINES 20-34 .. image-sg:: /gallery/images_contours_and_fields/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/images_contours_and_fields/images/sphx_glr_colormap_interactive_adjustment_001.png, /gallery/images_contours_and_fields/images/sphx_glr_colormap_interactive_adjustment_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python 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_images_contours_and_fields_colormap_interactive_adjustment.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: colormap_interactive_adjustment.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: colormap_interactive_adjustment.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_