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

    Click :ref:`here <sphx_glr_download_auto_examples_plot_colors.py>` to download the full example code or run this example in your browser via Binder
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_plot_colors.py:


Colormaps alter your perception
===============================

Here I plot the function

.. math:: f(x, y) = \sin(x) + \cos(y)

with different colormaps.




.. code-block:: python


    import numpy as np
    import matplotlib.pyplot as plt

    x = np.linspace(-np.pi, np.pi, 300)
    xx, yy = np.meshgrid(x, x)
    z = np.cos(xx) + np.cos(yy)

    plt.figure()
    plt.imshow(z)

    plt.figure()
    plt.imshow(z, cmap=plt.cm.get_cmap('hot'))

    plt.figure()
    plt.imshow(z, cmap=plt.cm.get_cmap('Spectral'),
               interpolation='none')

    # Not needed for the Gallery.
    # Only for direct execution
    plt.show()




.. rst-class:: sphx-glr-horizontal


    *

      .. image:: /auto_examples/images/sphx_glr_plot_colors_001.png
            :class: sphx-glr-multi-img

    *

      .. image:: /auto_examples/images/sphx_glr_plot_colors_002.png
            :class: sphx-glr-multi-img

    *

      .. image:: /auto_examples/images/sphx_glr_plot_colors_003.png
            :class: sphx-glr-multi-img




You can define blocks in your source code
with interleaving prose.




.. code-block:: python


    print("This writes to stdout and will be",
          " displayed in the HTML file")




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

 Out:

 .. code-block:: none

    ('This writes to stdout and will be', ' displayed in the HTML file')


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


.. _sphx_glr_download_auto_examples_plot_colors.py:


.. only :: html

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


  .. container:: binder-badge

    .. image:: https://static.mybinder.org/badge.svg
      :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/plot_colors.ipynb
      :width: 150 px


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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