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

Skip to content

Commit 0f7fe0a

Browse files
committed
Merge branch 'master' of github.com:dmcdougall/scipy14-colormaps
2 parents da53ae7 + 925c510 commit 0f7fe0a

20 files changed

Lines changed: 556 additions & 0 deletions

perceptions/analysis.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
from skimage import io, color
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
from matplotlib import cm
5+
import matplotlib as mpl
6+
import pdb
7+
from scipy.optimize import curve_fit
8+
9+
mpl.rcParams.update({'font.size': 14})
10+
mpl.rcParams['font.sans-serif'] = 'Arev Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Helvetica, Avant Garde, sans-serif'
11+
mpl.rcParams['mathtext.fontset'] = 'custom'
12+
mpl.rcParams['mathtext.cal'] = 'cursive'
13+
mpl.rcParams['mathtext.rm'] = 'sans'
14+
mpl.rcParams['mathtext.tt'] = 'monospace'
15+
mpl.rcParams['mathtext.it'] = 'sans:italic'
16+
mpl.rcParams['mathtext.bf'] = 'sans:bold'
17+
mpl.rcParams['mathtext.sf'] = 'sans'
18+
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'
19+
20+
21+
## Get colormaps, from http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html
22+
23+
# Get a list of the colormaps in matplotlib. Ignore the ones that end with
24+
# '_r' because these are simply reversed versions of ones that don't end
25+
# with '_r'
26+
maps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
27+
nmaps = len(maps) + 1
28+
29+
# OR, to have colormaps separated into categories: http://matplotlib.org/examples/color/colormaps_reference.html
30+
31+
cmaps = [('Sequential', ['binary', 'Blues', 'BuGn', 'BuPu', 'gist_yarg',
32+
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
33+
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
34+
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
35+
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper',
36+
'gist_gray', 'gist_heat', 'gray', 'hot', 'pink',
37+
'spring', 'summer', 'winter']),
38+
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
39+
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'seismic']),
40+
('Qualitative', ['Accent', 'Dark2', 'hsv', 'Paired', 'Pastel1',
41+
'Pastel2', 'Set1', 'Set2', 'Set3', 'spectral']),
42+
('Miscellaneous', ['gist_earth', 'gist_ncar', 'gist_rainbow',
43+
'gist_stern', 'jet', 'brg', 'CMRmap', 'cubehelix',
44+
'gnuplot', 'gnuplot2', 'ocean', 'rainbow',
45+
'terrain', 'flag', 'prism'])]
46+
47+
ncmaps = len(cmaps)
48+
49+
x = np.linspace(0.0, 1.0, 100)
50+
51+
## Sequential colormaps
52+
53+
fig = plt.figure(figsize=(18,8))
54+
55+
# loop through maps
56+
# for i,m in enumerate(maps):
57+
i = 1
58+
for cmap_category, cmap_list in cmaps:
59+
60+
if 'Sequential' not in cmap_category:
61+
continue
62+
63+
flag = True
64+
65+
ax = fig.add_subplot(2, 1, i)
66+
if i==1:
67+
ax.set_title('Lightness $L^*$ along colormap index', fontsize=18)
68+
69+
for j, cmap in enumerate(cmap_list):
70+
71+
# Get rgb values for colormap
72+
rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]
73+
# hsv = matplotlib.colors.rgb_to_hsv(rgb).squeeze()
74+
75+
# Get colormap in CIE LAB. We want the L here.
76+
lab = color.rgb2lab(rgb)
77+
78+
# if cmap=='binary':
79+
# pdb.set_trace()
80+
81+
# Plot colormap L values
82+
if '(2)' in cmap_category:
83+
ax.scatter(x+j*0.83, lab[0,:,0], c=x, cmap=cmap, s=300, linewidths=0.1)
84+
ax.set_ylabel('Sequential MatLab', fontsize=18)
85+
ax.axis([0,11,0,100])
86+
else:
87+
ax.scatter(x+j*0.5, lab[0,::-1,0], c=x, cmap=cmap + '_r', s=300, linewidths=0.1)
88+
ax.set_ylabel('Sequential', fontsize=18)
89+
ax.axis([0,10.5,0,100])
90+
91+
ax.get_xaxis().set_ticks([])
92+
93+
i += 1
94+
95+
fig.subplots_adjust(left=0.04, right=0.99, bottom=0.05, top=0.93, hspace=0.1)
96+
fig.show()
97+
98+
fig.savefig('figures/lightness-sequential.png')
99+
100+
101+
## Non-sequential colormaps
102+
103+
fig = plt.figure(figsize=(18,10))
104+
105+
# loop through maps
106+
# for i,m in enumerate(maps):
107+
i = 1
108+
for cmap_category, cmap_list in cmaps:
109+
110+
if 'Sequential' in cmap_category:
111+
continue
112+
113+
flag = True
114+
115+
ax = fig.add_subplot(3, 1, i)
116+
if i==1:
117+
ax.set_title('Lightness $L^*$ along colormap index', fontsize=18)
118+
119+
for j, cmap in enumerate(cmap_list):
120+
121+
# Get rgb values for colormap
122+
rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]
123+
# hsv = matplotlib.colors.rgb_to_hsv(rgb).squeeze()
124+
125+
# Get colormap in CIE LAB. We want the L here.
126+
lab = color.rgb2lab(rgb)
127+
128+
# Plot colormap L values
129+
if 'Qualitative' in cmap_category:
130+
ax.scatter(x+j*1.3, lab[0,:,0], c=x, cmap=cmap, s=300, linewidths=0.1)
131+
ax.axis([0,13,0,100])
132+
elif 'Diverging' in cmap_category:
133+
ax.scatter(x+j*1.2, lab[0,::-1,0], c=x, cmap=cmap + '_r', s=300, linewidths=0.1)
134+
ax.axis([0,13,0,100])
135+
elif 'Miscellaneous' in cmap_category:
136+
ax.scatter(x+j*1.5, lab[0,::-1,0], c=x, cmap=cmap + '_r', s=300, linewidths=0.1)
137+
ax.axis([0,22,0,100])
138+
139+
ax.get_xaxis().set_ticks([])
140+
ax.set_ylabel(cmap_category, fontsize=18)
141+
142+
i += 1
143+
144+
fig.subplots_adjust(left=0.04, right=0.99, bottom=0.03, top=0.95, hspace=0.1)
145+
fig.show()
146+
fig.savefig('figures/lightness-rest.png')
147+
148+
# can't figure out this part. Curve fitting isn't looking right.
149+
150+
# ## Sequential colormap L* curve fitting
151+
152+
# def func(x, a, b, c):
153+
# return c + a * x ** b
154+
155+
# # xdata = np.linspace(0, 4, 50)
156+
157+
# # Loop through sequential colormaps and calculate the curve fit
158+
# # Then paste the exponent on the plot for each.
159+
# for j, cmap in enumerate(cmaps[0][1]): # Sequential colormaps
160+
161+
# # Get rgb values for colormap
162+
# rgb = cm.get_cmap(cmap + '_r')(x)[np.newaxis,:,:3]
163+
164+
# # Get colormap in CIE LAB. We want the L here.
165+
# lab = color.rgb2lab(rgb)
166+
167+
# popt, pcov = curve_fit(func, x, lab[0,:,0])
168+
169+
# print cmap, popt[1]
170+
171+
# # pdb.set_trace()

perceptions/figures/Cielab.jpg

60.3 KB
Loading
18.8 KB
Loading

perceptions/figures/albers-bw.pdf

10.2 KB
Binary file not shown.

perceptions/figures/albers.pdf

8.95 KB
Binary file not shown.
18.9 KB
Loading

perceptions/figures/div.png

33.8 KB
Loading
76.8 KB
Loading
701 KB
Loading
621 KB
Loading

0 commit comments

Comments
 (0)