66Reference for colormaps included with Matplotlib.
77
88A reversed version of each of these colormaps is available by appending
9- ``_r`` to the name, e.g., ``viridis_r` `.
9+ ``_r`` to the name, as shown in :ref:`reverse-cmap `.
1010
1111See :doc:`/tutorials/colors/colormaps` for an in-depth discussion about
12- colormaps, including colorblind-friendliness.
12+ colormaps, including colorblind-friendliness, and
13+ :doc:`/tutorials/colors/colormap-manipulation` for a guide to creating
14+ colormaps.
1315"""
1416
1517import numpy as np
1618import matplotlib .pyplot as plt
1719
18-
1920cmaps = [('Perceptually Uniform Sequential' , [
2021 'viridis' , 'plasma' , 'inferno' , 'magma' , 'cividis' ]),
2122 ('Sequential' , [
4041 'gist_rainbow' , 'rainbow' , 'jet' , 'turbo' , 'nipy_spectral' ,
4142 'gist_ncar' ])]
4243
43-
4444gradient = np .linspace (0 , 1 , 256 )
4545gradient = np .vstack ((gradient , gradient ))
4646
@@ -52,7 +52,7 @@ def plot_color_gradients(cmap_category, cmap_list):
5252 fig , axs = plt .subplots (nrows = nrows , figsize = (6.4 , figh ))
5353 fig .subplots_adjust (top = 1 - .35 / figh , bottom = .15 / figh , left = 0.2 , right = 0.99 )
5454
55- axs [0 ].set_title (cmap_category + ' colormaps' , fontsize = 14 )
55+ axs [0 ].set_title (f" { cmap_category } colormaps" , fontsize = 14 )
5656
5757 for ax , cmap_name in zip (axs , cmap_list ):
5858 ax .imshow (gradient , aspect = 'auto' , cmap = cmap_name )
@@ -67,7 +67,21 @@ def plot_color_gradients(cmap_category, cmap_list):
6767for cmap_category , cmap_list in cmaps :
6868 plot_color_gradients (cmap_category , cmap_list )
6969
70- plt .show ()
70+
71+ ###############################################################################
72+ # .. _reverse-cmap:
73+ #
74+ # Reversed colormaps
75+ # ------------------
76+ #
77+ # Append ``_r`` to the name of any built-in colormap to get the reversed
78+ # version:
79+
80+ plot_color_gradients ("Original and reversed " , ['viridis' , 'viridis_r' ])
81+
82+ # %%
83+ # The built-in reversed colormaps are generated using `.Colormap.reversed`.
84+ # For an example, see :ref:`reversing-colormap`
7185
7286#############################################################################
7387#
0 commit comments