1
1
'''
2
- Show what matplotlib colormaps look like in grayscale.
2
+ ==================================
3
+ Grayscale version of the colormaps
4
+ ==================================
5
+
6
+ Show what Matplotlib colormaps look like in grayscale.
3
7
Uses lightness L* as a proxy for grayscale value.
4
8
'''
5
9
6
- from colormaps import cmaps
7
-
8
- #from skimage import color
9
- # we are using a local copy of colorconv from scikit-image to reduce dependencies.
10
- # You should probably use the one from scikit-image in most cases.
11
10
import numpy as np
11
+ import matplotlib as mpl
12
12
import matplotlib .pyplot as plt
13
13
from matplotlib import cm
14
- import matplotlib as mpl
15
14
from colorspacious import cspace_converter
15
+ from colormaps import cmaps # the colormaps, grouped by category
16
16
17
17
mpl .rcParams .update ({'font.size' : 14 })
18
18
19
-
20
- # indices to step through colormap
19
+ # Indices to step through colormap.
21
20
x = np .linspace (0.0 , 1.0 , 100 )
22
21
23
- # nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
24
22
gradient = np .linspace (0 , 1 , 256 )
25
23
gradient = np .vstack ((gradient , gradient ))
26
24
25
+
27
26
def plot_color_gradients (cmap_category , cmap_list ):
28
- nrows = len (cmap_list )
29
- fig , axes = plt .subplots (nrows = nrows , ncols = 2 )
27
+ fig , axes = plt .subplots (nrows = len (cmap_list ), ncols = 2 )
30
28
fig .subplots_adjust (top = 0.95 , bottom = 0.01 , left = 0.2 , right = 0.99 ,
31
29
wspace = 0.05 )
32
30
fig .suptitle (cmap_category + ' colormaps' , fontsize = 14 , y = 1.0 , x = 0.6 )
33
31
34
32
for ax , name in zip (axes , cmap_list ):
35
33
36
- # Get rgb values for colormap
34
+ # Get RGB values for colormap.
37
35
rgb = cm .get_cmap (plt .get_cmap (name ))(x )[np .newaxis ,:,:3 ]
38
36
39
37
# Get colormap in CAM02-UCS colorspace. We want the lightness.
@@ -49,9 +47,9 @@ def plot_color_gradients(cmap_category, cmap_list):
49
47
fig .text (x_text , y_text , name , va = 'center' , ha = 'right' , fontsize = 10 )
50
48
51
49
# Turn off *all* ticks & spines, not just the ones with colormaps.
52
- for ax in axes :
53
- ax [ 0 ] .set_axis_off ()
54
- ax [ 1 ]. set_axis_off ()
50
+ for ax in axes . flat :
51
+ ax .set_axis_off ()
52
+
55
53
plt .show ()
56
54
57
55
0 commit comments