|
14 | 14 | import matplotlib.pyplot as plt
|
15 | 15 | from matplotlib import cm
|
16 | 16 | import matplotlib as mpl
|
| 17 | +from colorspacious import cspace_converter |
17 | 18 |
|
18 | 19 | mpl.rcParams.update({'font.size': 12})
|
19 | 20 | mpl.rcParams['font.sans-serif'] = ('Arev Sans, Bitstream Vera Sans, '
|
|
57 | 58 | # Get rgb values for colormap
|
58 | 59 | rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]
|
59 | 60 |
|
60 |
| - # Get colormap in CIE LAB. We want the L here. |
61 |
| - lab = color.rgb2lab(rgb) |
| 61 | + # Get colormap in CAM02-UCS colorspace. We want the lightness. |
| 62 | + lab = cspace_converter("sRGB1", "CAM02-UCS")(rgb) |
62 | 63 |
|
63 | 64 | # Plot colormap L values
|
64 | 65 | # Do separately for each category so each plot can be pretty
|
65 | 66 | # to make scatter markers change color along plot:
|
66 | 67 | # http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
|
67 | 68 | if cmap_category=='Perceptually Uniform Sequential':
|
68 | 69 | dc = 1.15 # spacing between colormaps
|
69 |
| - ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap, |
| 70 | + ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap, |
70 | 71 | s=300, linewidths=0.)
|
71 | 72 | if i==2:
|
72 | 73 | ax.axis([-0.1,4.1,0,100])
|
|
76 | 77 |
|
77 | 78 | elif cmap_category=='Sequential':
|
78 | 79 | dc = 0.6 # spacing between colormaps
|
79 |
| - ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap + '_r', |
| 80 | + # These colormaps all start at high lightness but we want them |
| 81 | + # reversed to look nice in the plot, so reverse the order. |
| 82 | + ax.scatter(x+j*dc, lab[0,::-1,0], c=x[::-1], cmap=cmap, |
80 | 83 | s=300, linewidths=0.)
|
81 | 84 | if i==2:
|
82 | 85 | ax.axis([-0.1,4.1,0,100])
|
|
0 commit comments