Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6756c81

Browse files
committed
fixed ordering of lightness plots and changed from getting lightness from CIELAB to CAM02-UCS colorspace
1 parent bc79db4 commit 6756c81

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

doc/users/plotting/colormaps/lightness.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import matplotlib.pyplot as plt
1515
from matplotlib import cm
1616
import matplotlib as mpl
17+
from colorspacious import cspace_converter
1718

1819
mpl.rcParams.update({'font.size': 12})
1920

@@ -46,16 +47,16 @@
4647
# Get rgb values for colormap
4748
rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]
4849

49-
# Get colormap in CIE LAB. We want the L here.
50-
lab = color.rgb2lab(rgb)
50+
# Get colormap in CAM02-UCS colorspace. We want the lightness.
51+
lab = cspace_converter("sRGB1", "CAM02-UCS")(rgb)
5152

5253
# Plot colormap L values
5354
# Do separately for each category so each plot can be pretty
5455
# to make scatter markers change color along plot:
5556
# http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
5657
if cmap_category=='Perceptually Uniform Sequential':
5758
dc = 1.15 # spacing between colormaps
58-
ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap,
59+
ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
5960
s=300, linewidths=0.)
6061
if i==2:
6162
ax.axis([-0.1,4.1,0,100])
@@ -65,7 +66,9 @@
6566

6667
elif cmap_category=='Sequential':
6768
dc = 0.6 # spacing between colormaps
68-
ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap + '_r',
69+
# These colormaps all start at high lightness but we want them
70+
# reversed to look nice in the plot, so reverse the order.
71+
ax.scatter(x+j*dc, lab[0,::-1,0], c=x[::-1], cmap=cmap,
6972
s=300, linewidths=0.)
7073
if i==2:
7174
ax.axis([-0.1,4.1,0,100])

0 commit comments

Comments
 (0)