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

Skip to content

Commit 8ee7460

Browse files
committed
Add colormap references based on show_colormaps
1 parent 97afb7f commit 8ee7460

6 files changed

Lines changed: 161 additions & 0 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Reference for "diverging" colormaps.
3+
4+
Diverging colormaps have a median value (usually light in color) and vary
5+
smoothly to two different color tones at high and low values. Diverging
6+
colormaps are ideal when your data has a median value that is significant (e.g.
7+
0, such that positive and negative values are represented by different colors
8+
of the colormap).
9+
"""
10+
import numpy as np
11+
import matplotlib.pyplot as plt
12+
13+
14+
gradient = np.linspace(0, 1, 256)
15+
gradient = np.vstack((gradient, gradient))
16+
17+
# Note that any of these colormaps can be reversed by appending '_r'.
18+
cmaps = ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy',
19+
'RdYlBu', 'RdYlGn', 'seismic']
20+
21+
fig, axes = plt.subplots(nrows=len(cmaps))
22+
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
23+
24+
for ax, m in zip(axes, cmaps):
25+
ax.set_axis_off()
26+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(m))
27+
pos = list(ax.get_position().bounds)
28+
x_text = pos[0] - 0.01
29+
y_text = pos[1] + pos[3]/2.
30+
fig.text(x_text, y_text, m, va='center', ha='right')
31+
32+
plt.show()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Reference for "miscellaneous" colormaps.
3+
"""
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
7+
8+
gradient = np.linspace(0, 1, 256)
9+
gradient = np.vstack((gradient, gradient))
10+
11+
# Note that any of these colormaps can be reversed by appending '_r'.
12+
cmaps = ['flag', 'gist_earth', 'gist_ncar', 'gist_rainbow', 'gist_stern',
13+
'jet', 'prism', 'brg', 'CMRmap', 'cubehelix', 'gnuplot', 'gnuplot2',
14+
'ocean', 'rainbow', 'terrain']
15+
16+
fig, axes = plt.subplots(nrows=len(cmaps))
17+
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
18+
19+
for ax, m in zip(axes, cmaps):
20+
ax.set_axis_off()
21+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(m))
22+
pos = list(ax.get_position().bounds)
23+
x_text = pos[0] - 0.01
24+
y_text = pos[1] + pos[3]/2.
25+
fig.text(x_text, y_text, m, va='center', ha='right')
26+
27+
plt.show()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Reference for "qualitative" colormaps.
3+
4+
Qualitative colormaps vary rapidly in color. These colormaps are useful for
5+
choosing a set of discrete colors. For example::
6+
7+
color_list = plt.cm.Set3(np.linspace(0, 1, 12))
8+
9+
gives a list of RGB colors that are good for plotting a series of lines on
10+
a dark background.
11+
"""
12+
import numpy as np
13+
import matplotlib.pyplot as plt
14+
15+
16+
gradient = np.linspace(0, 1, 256)
17+
gradient = np.vstack((gradient, gradient))
18+
19+
# Note that any of these colormaps can be reversed by appending '_r'.
20+
cmaps = ['Accent', 'Dark2', 'hsv', 'Paired', 'Pastel1', 'Pastel2', 'Set1',
21+
'Set2', 'Set3', 'spectral']
22+
23+
fig, axes = plt.subplots(nrows=len(cmaps))
24+
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
25+
26+
for ax, m in zip(axes, cmaps):
27+
ax.set_axis_off()
28+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(m))
29+
pos = list(ax.get_position().bounds)
30+
x_text = pos[0] - 0.01
31+
y_text = pos[1] + pos[3]/2.
32+
fig.text(x_text, y_text, m, va='center', ha='right')
33+
34+
plt.show()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Reference for "sequential" colormaps.
3+
4+
Sequential colormaps are approximately monochromatic colormaps going from low
5+
saturation (e.g. white) to high saturation (e.g. a bright blue). Sequential
6+
colormaps are ideal for representing most scientific data since they show
7+
a clear progression from low-to-high values.
8+
"""
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
12+
13+
gradient = np.linspace(0, 1, 256)
14+
gradient = np.vstack((gradient, gradient))
15+
16+
# Note that any of these colormaps can be reversed by appending '_r'.
17+
cmaps = ['binary', 'Blues', 'BuGn', 'BuPu', 'gist_yarg', 'GnBu', 'Greens',
18+
'Greys', 'Oranges', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'Purples',
19+
'RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']
20+
21+
fig, axes = plt.subplots(nrows=len(cmaps))
22+
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
23+
24+
for ax, m in zip(axes, cmaps):
25+
ax.set_axis_off()
26+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(m))
27+
pos = list(ax.get_position().bounds)
28+
x_text = pos[0] - 0.01
29+
y_text = pos[1] + pos[3]/2.
30+
fig.text(x_text, y_text, m, va='center', ha='right')
31+
32+
plt.show()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Reference for "sequential" colormaps.
3+
4+
These are sequential colormaps, which vary smoothly between two color tones.
5+
Unlike the sequential colormaps in the first example, these either vary between
6+
two saturated tones (instead of being nearly monochromatic) or have a reversed
7+
progression (decreasing in saturation for increasing value). Note, however,
8+
that any colormap can be reversed by appending "_r" (e.g., "pink_r").
9+
"""
10+
import numpy as np
11+
import matplotlib.pyplot as plt
12+
13+
14+
gradient = np.linspace(0, 1, 256)
15+
gradient = np.vstack((gradient, gradient))
16+
17+
# Note that any of these colormaps can be reversed by appending '_r'.
18+
cmaps = ['afmhot', 'autumn', 'bone', 'cool', 'copper', 'gist_gray',
19+
'gist_heat', 'gray', 'hot', 'pink', 'spring', 'summer', 'winter']
20+
21+
fig, axes = plt.subplots(nrows=len(cmaps))
22+
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
23+
24+
for ax, m in zip(axes, cmaps):
25+
ax.set_axis_off()
26+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(m))
27+
pos = list(ax.get_position().bounds)
28+
x_text = pos[0] - 0.01
29+
y_text = pos[1] + pos[3]/2.
30+
fig.text(x_text, y_text, m, va='center', ha='right')
31+
32+
plt.show()

examples/pylab_examples/show_colormaps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# NOTE: This example has been superseded by examples in
2+
# 'color/colormaps_reference_*, but this example is referenced in the
3+
# "What's New" page, and the image tutorial.
4+
15
# This example comes from the Cookbook on www.scipy.org. According to the
26
# history, Andrew Straw did the conversion from an old page, but it is
37
# unclear who the original author is.

0 commit comments

Comments
 (0)