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

    Click :ref:`here <sphx_glr_download_gallery_color_colormap_reference.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_color_colormap_reference.py:


==================
Colormap reference
==================

Reference for colormaps included with Matplotlib.

A reversed version of each of these colormaps is available by appending
``_r`` to the name, e.g., ``viridis_r``.

See :doc:`/tutorials/colors/colormaps` for an in-depth discussion about
colormaps, including colorblind-friendliness.



.. code-block:: python


    import numpy as np
    import matplotlib.pyplot as plt


    cmaps = [('Perceptually Uniform Sequential', [
                'viridis', 'plasma', 'inferno', 'magma', 'cividis']),
             ('Sequential', [
                'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
                'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
                'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),
             ('Sequential (2)', [
                'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
                'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
                'hot', 'afmhot', 'gist_heat', 'copper']),
             ('Diverging', [
                'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
                'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),
             ('Qualitative', [
                'Pastel1', 'Pastel2', 'Paired', 'Accent',
                'Dark2', 'Set1', 'Set2', 'Set3',
                'tab10', 'tab20', 'tab20b', 'tab20c']),
             ('Miscellaneous', [
                'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
                'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',
                'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]


    nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
    gradient = np.linspace(0, 1, 256)
    gradient = np.vstack((gradient, gradient))


    def plot_color_gradients(cmap_category, cmap_list, nrows):
        fig, axes = plt.subplots(nrows=nrows)
        fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
        axes[0].set_title(cmap_category + ' colormaps', fontsize=14)

        for ax, name in zip(axes, cmap_list):
            ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
            pos = list(ax.get_position().bounds)
            x_text = pos[0] - 0.01
            y_text = pos[1] + pos[3]/2.
            fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

        # Turn off *all* ticks & spines, not just the ones with colormaps.
        for ax in axes:
            ax.set_axis_off()


    for cmap_category, cmap_list in cmaps:
        plot_color_gradients(cmap_category, cmap_list, nrows)

    plt.show()




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


    *

      .. image:: /gallery/color/images/sphx_glr_colormap_reference_001.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/color/images/sphx_glr_colormap_reference_002.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/color/images/sphx_glr_colormap_reference_003.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/color/images/sphx_glr_colormap_reference_004.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/color/images/sphx_glr_colormap_reference_005.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/color/images/sphx_glr_colormap_reference_006.png
            :class: sphx-glr-multi-img




------------

References
""""""""""

The use of the following functions, methods, classes and modules is shown
in this example:



.. code-block:: python


    import matplotlib
    matplotlib.colors
    matplotlib.axes.Axes.imshow
    matplotlib.figure.Figure.text
    matplotlib.axes.Axes.set_axis_off






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


.. _sphx_glr_download_gallery_color_colormap_reference.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
