

.. _sphx_glr_gallery_userdemo_colormap_normalizations_power.py:


=============================
Colormap Normalizations Power
=============================

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




.. image:: /gallery/userdemo/images/sphx_glr_colormap_normalizations_power_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

    N = 100
    X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]

    '''
    PowerNorm: Here a power-law trend in X partially obscures a rectified
    sine wave in Y. We can remove the power law using a PowerNorm.
    '''
    X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
    Z1 = (1 + np.sin(Y * 10.)) * X**(2.)

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

    pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=1./2.),
                           cmap='PuBu_r')
    fig.colorbar(pcm, ax=ax[0], extend='max')

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

    plt.show()

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



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

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