

.. _sphx_glr_gallery_userdemo_colormap_normalizations_lognorm.py:


===============================
Colormap Normalizations Lognorm
===============================

Demonstration of using norm to map colormaps onto data in non-linear ways.




.. image:: /gallery/userdemo/images/sphx_glr_colormap_normalizations_lognorm_001.png
    :align: center





.. code-block:: python


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

    '''
    Lognorm: Instead of pcolor log10(Z1) you can have colorbars that have
    the exponential labels using a norm.
    '''
    N = 100
    X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]

    # A low hump with a spike coming out of the top right.  Needs to have
    # z/colour axis on a log scale so we see both hump and spike.  linear
    # scale only shows the spike.
    Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) +  \
        0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)

    fig, ax = plt.subplots(2, 1)

    pcm = ax[0].pcolor(X, Y, Z1,
                       norm=colors.LogNorm(vmin=Z1.min(), vmax=Z1.max()),
                       cmap='PuBu_r')
    fig.colorbar(pcm, ax=ax[0], extend='max')

    pcm = ax[1].pcolor(X, Y, Z1, cmap='PuBu_r')
    fig.colorbar(pcm, ax=ax[1], extend='max')

    plt.show()

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



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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