6
6
Reference for colormaps included with Matplotlib.
7
7
8
8
A 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 `.
10
10
11
11
See :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.
13
15
"""
14
16
15
17
import numpy as np
16
18
import matplotlib .pyplot as plt
17
19
18
-
19
20
cmaps = [('Perceptually Uniform Sequential' , [
20
21
'viridis' , 'plasma' , 'inferno' , 'magma' , 'cividis' ]),
21
22
('Sequential' , [
40
41
'gist_rainbow' , 'rainbow' , 'jet' , 'turbo' , 'nipy_spectral' ,
41
42
'gist_ncar' ])]
42
43
43
-
44
44
gradient = np .linspace (0 , 1 , 256 )
45
45
gradient = np .vstack ((gradient , gradient ))
46
46
@@ -52,7 +52,7 @@ def plot_color_gradients(cmap_category, cmap_list):
52
52
fig , axs = plt .subplots (nrows = nrows , figsize = (6.4 , figh ))
53
53
fig .subplots_adjust (top = 1 - .35 / figh , bottom = .15 / figh , left = 0.2 , right = 0.99 )
54
54
55
- axs [0 ].set_title (cmap_category + ' colormaps' , fontsize = 14 )
55
+ axs [0 ].set_title (f" { cmap_category } colormaps" , fontsize = 14 )
56
56
57
57
for ax , cmap_name in zip (axs , cmap_list ):
58
58
ax .imshow (gradient , aspect = 'auto' , cmap = cmap_name )
@@ -67,7 +67,23 @@ def plot_color_gradients(cmap_category, cmap_list):
67
67
for cmap_category , cmap_list in cmaps :
68
68
plot_color_gradients (cmap_category , cmap_list )
69
69
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 when building the
84
+ # `.ColormapRegistry` by calling the ``reversed`` method on the built-in
85
+ # colormap objects. See :ref:`reversing-colormap` for more information about
86
+ # the ``reversed`` method.
71
87
72
88
#############################################################################
73
89
#
0 commit comments