Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50bb88a

Browse files
authored
Merge pull request#8156 from afvincent/add_missing_cmaps_to_perception_doc
DOC: Add missing cmaps to perception doc (fix for#8073)
2 parentsd10d9d9 +e442647 commit50bb88a

File tree

4 files changed

+121
-140
lines changed

4 files changed

+121
-140
lines changed
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# Have colormaps separated into categories:
22
# http://matplotlib.org/examples/color/colormaps_reference.html
33

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'])]
4+
cmaps= [('Perceptually Uniform Sequential', [
5+
'viridis','plasma','inferno','magma']),
6+
('Sequential', [
7+
'Greys','Purples','Blues','Greens','Oranges','Reds',
8+
'YlOrBr','YlOrRd','OrRd','PuRd','RdPu','BuPu',
9+
'GnBu','PuBu','YlGnBu','PuBuGn','BuGn','YlGn']),
10+
('Sequential (2)', [
11+
'binary','gist_yarg','gist_gray','gray','bone','pink',
12+
'spring','summer','autumn','winter','cool','Wistia',
13+
'hot','afmhot','gist_heat','copper']),
14+
('Diverging', [
15+
'PiYG','PRGn','BrBG','PuOr','RdGy','RdBu',
16+
'RdYlBu','RdYlGn','Spectral','coolwarm','bwr','seismic']),
17+
('Qualitative', [
18+
'Pastel1','Pastel2','Paired','Accent',
19+
'Dark2','Set1','Set2','Set3',
20+
'tab10','tab20','tab20b','tab20c']),
21+
('Miscellaneous', [
22+
'flag','prism','ocean','gist_earth','terrain','gist_stern',
23+
'gnuplot','gnuplot2','CMRmap','cubehelix','brg','hsv',
24+
'gist_rainbow','rainbow','jet','nipy_spectral','gist_ncar'])]

‎doc/users/plotting/colormaps/grayscale.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
'''
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.
37
Uses lightness L* as a proxy for grayscale value.
48
'''
59

6-
fromcolormapsimportcmaps
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.
1110
importnumpyasnp
11+
importmatplotlibasmpl
1212
importmatplotlib.pyplotasplt
1313
frommatplotlibimportcm
14-
importmatplotlibasmpl
1514
fromcolorspaciousimportcspace_converter
15+
fromcolormapsimportcmaps# the colormaps, grouped by category
1616

1717
mpl.rcParams.update({'font.size':14})
1818

19-
20-
# indices to step through colormap
19+
# Indices to step through colormap.
2120
x=np.linspace(0.0,1.0,100)
2221

23-
# nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
2422
gradient=np.linspace(0,1,256)
2523
gradient=np.vstack((gradient,gradient))
2624

25+
2726
defplot_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)
3028
fig.subplots_adjust(top=0.95,bottom=0.01,left=0.2,right=0.99,
3129
wspace=0.05)
3230
fig.suptitle(cmap_category+' colormaps',fontsize=14,y=1.0,x=0.6)
3331

3432
forax,nameinzip(axes,cmap_list):
3533

36-
# Getrgb values for colormap
34+
# GetRGB values for colormap.
3735
rgb=cm.get_cmap(plt.get_cmap(name))(x)[np.newaxis,:,:3]
3836

3937
# Get colormap in CAM02-UCS colorspace. We want the lightness.
@@ -49,9 +47,9 @@ def plot_color_gradients(cmap_category, cmap_list):
4947
fig.text(x_text,y_text,name,va='center',ha='right',fontsize=10)
5048

5149
# Turn off *all* ticks & spines, not just the ones with colormaps.
52-
foraxinaxes:
53-
ax[0].set_axis_off()
54-
ax[1].set_axis_off()
50+
foraxinaxes.flat:
51+
ax.set_axis_off()
52+
5553
plt.show()
5654

5755

Lines changed: 65 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,100 @@
11
'''
2+
==========================
3+
Lightness of the colormaps
4+
==========================
5+
26
For each colormap, plot the lightness parameter L* from CIELAB colorspace
37
along the y axis vs index through the colormap. Colormaps are examined in
48
categories as in the original matplotlib gallery of colormaps.
59
'''
610

7-
fromcolormapsimportcmaps
811
importnumpyasnp
12+
importmatplotlibasmpl
913
importmatplotlib.pyplotasplt
1014
frommatplotlibimportcm
11-
importmatplotlibasmpl
1215
fromcolorspaciousimportcspace_converter
16+
fromcolormapsimportcmaps# the colormaps, grouped by category
1317

1418
mpl.rcParams.update({'font.size':12})
1519

16-
# indices to step through colormap
20+
# Number of colormap per subplot for particular cmap categories
21+
_DSUBS= {'Perceptually Uniform Sequential':4,'Sequential':6,
22+
'Sequential (2)':6,'Diverging':6,'Qualitative':4,
23+
'Miscellaneous':6}
24+
25+
# Spacing between the colormaps of a subplot
26+
_DC= {'Perceptually Uniform Sequential':1.4,'Sequential':0.7,
27+
'Sequential (2)':1.4,'Diverging':1.4,'Qualitative':1.4,
28+
'Miscellaneous':1.4}
29+
30+
# Indices to step through colormap
1731
x=np.linspace(0.0,1.0,100)
1832

1933
# Do plot
2034
forcmap_category,cmap_listincmaps:
2135

22-
# Do subplots so that colormaps have enough space. 5 per subplot?
23-
dsub=5# number of colormaps per subplot
24-
ifcmap_category=='Diverging':# because has 12 colormaps
25-
dsub=6
26-
elifcmap_category=='Sequential (2)':
27-
dsub=6
28-
elifcmap_category=='Sequential':
29-
dsub=7
30-
nsubplots=int(np.ceil(len(cmap_list)/float(dsub)))
31-
32-
fig=plt.figure(figsize=(7,2.6*nsubplots))
36+
# Do subplots so that colormaps have enough space.
37+
# Default is 6 colormaps per subplot.
38+
dsub=_DSUBS.get(cmap_category,6)
39+
nsubplots=int(np.ceil(len(cmap_list)/float(dsub)))
3340

34-
fori,subplotinenumerate(range(nsubplots)):
41+
# squeeze=False to handle similarly the case of a single subplot
42+
fig,axes=plt.subplots(nrows=nsubplots,squeeze=False,
43+
figsize=(7,2.6*nsubplots))
3544

36-
locs= []# locations for text labels
45+
fori,axinenumerate(axes.flat):
3746

38-
ax=fig.add_subplot(nsubplots,1,i+1)
47+
locs=[]# locations for text labels
3948

4049
forj,cmapinenumerate(cmap_list[i*dsub:(i+1)*dsub]):
4150

42-
# Get rgb values for colormap
43-
rgb=cm.get_cmap(cmap)(x)[np.newaxis,:,:3]
44-
45-
# Get colormap in CAM02-UCS colorspace. We want the lightness.
51+
# Get RGB values for colormap and convert the colormap in
52+
# CAM02-UCS colorspace. lab[0, :, 0] is the lightness.
53+
rgb=cm.get_cmap(cmap)(x)[np.newaxis, :, :3]
4654
lab=cspace_converter("sRGB1","CAM02-UCS")(rgb)
4755

48-
# Plot colormap L values
49-
#Do separately for each categoryso each plot can be pretty
50-
#to make scatter markers changecolor along plot:
56+
# Plot colormap L values. Do separately for each category
57+
# so each plot can be pretty. To make scatter markers change
58+
# color along plot:
5159
# http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
52-
ifcmap_category=='Perceptually Uniform Sequential':
53-
dc=1.15# spacing between colormaps
54-
ax.scatter(x+j*dc,lab[0,:,0],c=x,cmap=cmap,
55-
s=300,linewidths=0.)
56-
ifi==2:
57-
ax.axis([-0.1,4.1,0,100])
58-
else:
59-
ax.axis([-0.1,4.7,0,100])
60-
locs.append(x[-1]+j*dc)# store locations for colormap labels
61-
62-
elifcmap_category=='Sequential':
63-
dc=0.6# spacing between colormaps
60+
61+
ifcmap_category=='Sequential':
6462
# These colormaps all start at high lightness but we want them
6563
# reversed to look nice in the plot, so reverse the order.
66-
ax.scatter(x+j*dc,lab[0,::-1,0],c=x[::-1],cmap=cmap,
67-
s=300,linewidths=0.)
68-
ifi==2:
69-
ax.axis([-0.1,4.1,0,100])
70-
else:
71-
ax.axis([-0.1,4.7,0,100])
72-
locs.append(x[-1]+j*dc)# store locations for colormap labels
73-
74-
elifcmap_category=='Sequential (2)':
75-
dc=1.15
76-
ax.scatter(x+j*dc,lab[0,:,0],c=x,cmap=cmap,
77-
s=300,linewidths=0.)
78-
ax.axis([-0.1,7.0,0,100])
79-
# store locations for colormap labels
80-
locs.append(x[-1]+j*dc)
81-
82-
elifcmap_category=='Diverging':
83-
dc=1.2
84-
ax.scatter(x+j*dc,lab[0,:,0],c=x,cmap=cmap,
85-
s=300,linewidths=0.)
86-
ax.axis([-0.1,7.1,0,100])
87-
# store locations for colormap labels
88-
locs.append(x[int(x.size/2.)]+j*dc)
89-
elifcmap_category=='Qualitative':
90-
dc=1.3
91-
ax.scatter(x+j*dc,lab[0,:,0],c=x,cmap=cmap,
92-
s=300,linewidths=0.)
93-
ax.axis([-0.1,6.3,0,100])
94-
# store locations for colormap labels
95-
locs.append(x[int(x.size/2.)]+j*dc)
96-
97-
elifcmap_category=='Miscellaneous':
98-
dc=1.25
99-
ax.scatter(x+j*dc,lab[0,:,0],c=x,cmap=cmap,
100-
s=300,linewidths=0.)
101-
ax.axis([-0.1,6.1,0,100])
102-
# store locations for colormap labels
103-
locs.append(x[int(x.size/2.)]+j*dc)
104-
105-
# Set up labels for colormaps
106-
ax.xaxis.set_ticks_position('top')
107-
ticker=mpl.ticker.FixedLocator(locs)
108-
ax.xaxis.set_major_locator(ticker)
109-
formatter=mpl.ticker.FixedFormatter(cmap_list[i*dsub:(i+1)*dsub])
110-
ax.xaxis.set_major_formatter(formatter)
111-
labels=ax.get_xticklabels()
112-
forlabelinlabels:
113-
label.set_rotation(60)
64+
y_=lab[0, ::-1,0]
65+
c_=x[::-1]
66+
else:
67+
y_=lab[0, :,0]
68+
c_=x
69+
70+
dc=_DC.get(cmap_category,1.4)# cmaps horizontal spacing
71+
ax.scatter(x+j*dc,y_,c=c_,cmap=cmap,s=300,linewidths=0.0)
72+
73+
# Store locations for colormap labels
74+
ifcmap_categoryin ('Perceptually Uniform Sequential',
75+
'Sequential'):
76+
locs.append(x[-1]+j*dc)
77+
elifcmap_categoryin ('Diverging','Qualitative',
78+
'Miscellaneous','Sequential (2)'):
79+
locs.append(x[int(x.size/2.)]+j*dc)
80+
81+
# Set up the axis limits:
82+
# * the 1st subplot is used as a reference for the x-axis limits
83+
# * lightness values goes from 0 to 100 (y-axis limits)
84+
ax.set_xlim(axes[0,0].get_xlim())
85+
ax.set_ylim(0.0,100.0)
86+
87+
# Set up labels for colormaps
88+
ax.xaxis.set_ticks_position('top')
89+
ticker=mpl.ticker.FixedLocator(locs)
90+
ax.xaxis.set_major_locator(ticker)
91+
formatter=mpl.ticker.FixedFormatter(cmap_list[i*dsub:(i+1)*dsub])
92+
ax.xaxis.set_major_formatter(formatter)
93+
ax.xaxis.set_tick_params(rotation=50)
11494

11595
ax.set_xlabel(cmap_category+' colormaps',fontsize=14)
11696
fig.text(0.0,0.55,'Lightness $L^*$',fontsize=12,
11797
transform=fig.transFigure,rotation=90)
11898

119-
fig.tight_layout(h_pad=0.05,pad=1.5)
99+
fig.tight_layout(h_pad=0.0,pad=1.5)
120100
plt.show()

‎examples/color/colormaps_reference.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,27 @@
4242

4343
# Have colormaps separated into categories:
4444
# http://matplotlib.org/examples/color/colormaps_reference.html
45-
cmaps= [('Perceptually Uniform Sequential',
46-
['viridis','inferno','plasma','magma']),
47-
('Sequential', ['Blues','BuGn','BuPu',
48-
'GnBu','Greens','Greys','Oranges','OrRd',
49-
'PuBu','PuBuGn','PuRd','Purples','RdPu',
50-
'Reds','YlGn','YlGnBu','YlOrBr','YlOrRd']),
51-
('Sequential (2)', ['afmhot','autumn','bone','cool',
52-
'copper','gist_heat','gray','hot',
53-
'pink','spring','summer','winter']),
54-
('Diverging', ['BrBG','bwr','coolwarm','PiYG','PRGn','PuOr',
55-
'RdBu','RdGy','RdYlBu','RdYlGn','Spectral',
56-
'seismic']),
57-
('Qualitative', ['Accent','Dark2','Paired','Pastel1',
58-
'Pastel2','Set1','Set2','Set3','tab10',
59-
'tab20','tab20b','tab20c']),
60-
('Miscellaneous', ['gist_earth','terrain','ocean','gist_stern',
61-
'brg','CMRmap','cubehelix',
62-
'gnuplot','gnuplot2','gist_ncar',
63-
'nipy_spectral','jet','rainbow',
64-
'gist_rainbow','hsv','flag','prism'])]
45+
cmaps= [('Perceptually Uniform Sequential', [
46+
'viridis','plasma','inferno','magma']),
47+
('Sequential', [
48+
'Greys','Purples','Blues','Greens','Oranges','Reds',
49+
'YlOrBr','YlOrRd','OrRd','PuRd','RdPu','BuPu',
50+
'GnBu','PuBu','YlGnBu','PuBuGn','BuGn','YlGn']),
51+
('Sequential (2)', [
52+
'binary','gist_yarg','gist_gray','gray','bone','pink',
53+
'spring','summer','autumn','winter','cool','Wistia',
54+
'hot','afmhot','gist_heat','copper']),
55+
('Diverging', [
56+
'PiYG','PRGn','BrBG','PuOr','RdGy','RdBu',
57+
'RdYlBu','RdYlGn','Spectral','coolwarm','bwr','seismic']),
58+
('Qualitative', [
59+
'Pastel1','Pastel2','Paired','Accent',
60+
'Dark2','Set1','Set2','Set3',
61+
'tab10','tab20','tab20b','tab20c']),
62+
('Miscellaneous', [
63+
'flag','prism','ocean','gist_earth','terrain','gist_stern',
64+
'gnuplot','gnuplot2','CMRmap','cubehelix','brg','hsv',
65+
'gist_rainbow','rainbow','jet','nipy_spectral','gist_ncar'])]
6566

6667

6768
nrows=max(len(cmap_list)forcmap_category,cmap_listincmaps)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp