

.. _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
            :scale: 47

    *

      .. image:: /auto_examples/images/sphx_glr_plot_colors_002.png
            :scale: 47

    *

      .. image:: /auto_examples/images/sphx_glr_plot_colors_003.png
            :scale: 47




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::

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


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



.. only :: html

 .. container:: sphx-glr-footer


  .. 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>`_
