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

Skip to content

Commit e3bdf44

Browse files
committed
Add new category for perceptually uniform colormaps
Refactor to reduce duplication
1 parent db403c3 commit e3bdf44

File tree

4 files changed

+43
-68
lines changed

4 files changed

+43
-68
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Have colormaps separated into categories:
2+
# http://matplotlib.org/examples/color/colormaps_reference.html
3+
4+
cmaps = [('Perceptually Uniform Sequential',
5+
['viridis', 'inferno', 'plasma', 'magma']),
6+
('Sequential', ['Blues', 'BuGn', 'BuPu',
7+
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
8+
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
9+
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
10+
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool',
11+
'copper', 'gist_heat', 'gray', 'hot',
12+
'pink', 'spring', 'summer', 'winter']),
13+
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
14+
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
15+
'seismic']),
16+
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
17+
'Pastel2', 'Set1', 'Set2', 'Set3']),
18+
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
19+
'brg', 'CMRmap', 'cubehelix',
20+
'gnuplot', 'gnuplot2', 'gist_ncar',
21+
'nipy_spectral', 'jet', 'rainbow',
22+
'gist_rainbow', 'hsv', 'flag', 'prism'])]

doc/users/plotting/colormaps/grayscale.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
'''
55

66
import colorconv as color
7+
8+
from colormaps import cmaps
9+
710
#from skimage import color
8-
# we are using a local copy of colorconv from scikit-image to reduce dependencies.
9-
# You should probably use the one from scikit-image in most cases.
11+
# we are using a local copy of colorconv from scikit-image to reduce dependencies.
12+
# You should probably use the one from scikit-image in most cases.
1013
import numpy as np
1114
import matplotlib.pyplot as plt
1215
from matplotlib import cm
@@ -24,27 +27,6 @@
2427
mpl.rcParams['mathtext.sf'] = 'sans'
2528
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'
2629

27-
# Have colormaps separated into categories:
28-
# http://matplotlib.org/examples/color/colormaps_reference.html
29-
30-
cmaps = [('Sequential', ['Blues', 'BuGn', 'BuPu',
31-
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
32-
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
33-
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
34-
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper',
35-
'gist_heat', 'gray', 'hot', 'inferno', 'magma',
36-
'pink', 'plasma', 'spring', 'summer', 'viridis',
37-
'winter']),
38-
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
39-
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
40-
'seismic']),
41-
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
42-
'Pastel2', 'Set1', 'Set2', 'Set3']),
43-
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
44-
'brg', 'CMRmap', 'cubehelix',
45-
'gnuplot', 'gnuplot2', 'gist_ncar',
46-
'nipy_spectral', 'jet', 'rainbow',
47-
'gist_rainbow', 'hsv', 'flag', 'prism'])]
4830

4931
# indices to step through colormap
5032
x = np.linspace(0.0, 1.0, 100)

doc/users/plotting/colormaps/lightness.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
'''
2-
For each colormap, plot the lightness parameter L* from CIELAB colorspace
3-
along the y axis vs index through the colormap. Colormaps are examined in
2+
For each colormap, plot the lightness parameter L* from CIELAB colorspace
3+
along the y axis vs index through the colormap. Colormaps are examined in
44
categories as in the original matplotlib gallery of colormaps.
55
'''
66

77
import colorconv as color
8+
from colormaps import cmaps
89
#from skimage import color
910
# we are using a local copy of colorconv from scikit-image to
1011
# reduce dependencies.
11-
# You should probably use the one from scikit-image in most cases.
12+
# You should probably use the one from scikit-image in most cases.
1213
import numpy as np
1314
import matplotlib.pyplot as plt
1415
from matplotlib import cm
@@ -26,28 +27,6 @@
2627
mpl.rcParams['mathtext.sf'] = 'sans'
2728
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'
2829

29-
# Have colormaps separated into categories:
30-
# http://matplotlib.org/examples/color/colormaps_reference.html
31-
32-
cmaps = [('Sequential', ['Blues', 'BuGn', 'BuPu',
33-
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
34-
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
35-
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
36-
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper',
37-
'gist_heat', 'gray', 'hot', 'inferno', 'magma',
38-
'pink', 'plasma', 'spring', 'summer', 'viridis',
39-
'winter']),
40-
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
41-
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
42-
'seismic']),
43-
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
44-
'Pastel2', 'Set1', 'Set2', 'Set3']),
45-
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
46-
'brg', 'CMRmap', 'cubehelix',
47-
'gnuplot', 'gnuplot2', 'gist_ncar',
48-
'nipy_spectral', 'jet', 'rainbow',
49-
'gist_rainbow', 'hsv', 'flag', 'prism'])]
50-
5130
# indices to step through colormap
5231
x = np.linspace(0.0, 1.0, 100)
5332

@@ -84,7 +63,17 @@
8463
# Do separately for each category so each plot can be pretty
8564
# to make scatter markers change color along plot:
8665
# http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
87-
if cmap_category=='Sequential':
66+
if cmap_category=='Perceptually Uniform Sequential':
67+
dc = 1.15 # spacing between colormaps
68+
ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap,
69+
s=300, linewidths=0.)
70+
if i==2:
71+
ax.axis([-0.1,4.1,0,100])
72+
else:
73+
ax.axis([-0.1,4.7,0,100])
74+
locs.append(x[-1]+j*dc) # store locations for colormap labels
75+
76+
elif cmap_category=='Sequential':
8877
dc = 0.6 # spacing between colormaps
8978
ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap + '_r',
9079
s=300, linewidths=0.)

examples/color/colormaps_reference.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,7 @@
3535
import numpy as np
3636
import matplotlib.pyplot as plt
3737

38-
39-
cmaps = [('Sequential', ['Blues', 'BuGn', 'BuPu',
40-
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
41-
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
42-
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
43-
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper',
44-
'gist_heat', 'gray', 'hot', 'inferno', 'magma',
45-
'pink', 'plasma', 'spring', 'summer', 'viridis',
46-
'winter']),
47-
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
48-
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
49-
'seismic']),
50-
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
51-
'Pastel2', 'Set1', 'Set2', 'Set3']),
52-
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
53-
'brg', 'CMRmap', 'cubehelix',
54-
'gnuplot', 'gnuplot2', 'gist_ncar',
55-
'nipy_spectral', 'jet', 'rainbow',
56-
'gist_rainbow', 'hsv', 'flag', 'prism'])]
38+
from colormaps import cmaps
5739

5840

5941
nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)

0 commit comments

Comments
 (0)