-
Notifications
You must be signed in to change notification settings - Fork 906
/
Copy pathcolormaps.py
74 lines (56 loc) · 2.43 KB
/
colormaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import pathlib
import numpy as np
import matplotlib.pyplot as plt
ROOT_DIR = pathlib.Path(__file__).parent.parent
sys.path.append(str(ROOT_DIR / "fonts"))
import custom_fonts # noqa
figsize = 4.0, 0.25
fig = plt.figure(figsize=figsize)
ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1)
ymin, ymax= 0, 1
xmin, xmax = 0, figsize[0]/figsize[1]
# Uniform colormaps
# -----------------------------------------------------------------------------
cmaps = ('viridis', 'plasma', 'inferno', 'magma', 'cividis',
'PRGn', 'PiYG', 'RdYlGn', 'BrBG', 'RdGy', 'PuOr', 'RdBu',
'RdYlBu', 'Spectral', 'coolwarm', 'bwr', 'seismic',
'tab10', 'tab20', 'tab20b', 'tab20c',
'Pastel1', 'Pastel2', 'Paired',
'Set1', 'Set2', 'Set3', 'Accent', 'Dark2',
'Greys', 'Reds', 'Oranges', 'YlOrBr', 'YlOrRd', 'OrRd',
'PuRd', 'RdPu', 'BuPu', 'Purples', 'YlGnBu', 'Blues',
'PuBu', 'GnBu', 'PuBuGn', 'BuGn', 'Greens', 'YlGn',
'bone', 'gray', 'pink', 'afmhot', 'hot', 'gist_heat', 'copper',
'Wistia', 'autumn', 'summer', 'spring', 'cool', 'winter',
'twilight', 'twilight_shifted', 'hsv',
'terrain', 'ocean', 'gist_earth', 'cubehelix', 'rainbow'
)
for cmap in cmaps:
n = 512
if cmap in ['tab10']: n = 10
if cmap in ['tab20', 'tab20b', 'tab20c']: n = 20
if cmap in ['Pastel1', 'Set1']: n = 9
if cmap in ['Pastel2', 'Accent', 'Dark2', 'Set2']: n = 8
if cmap in ['Set3']: n = 12
if cmap in ['Greys']: n = 11
Z = np.linspace(0, 1, n).reshape(1, n)
ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=plt.get_cmap(cmap))
ax.set_xlim(xmin, xmax), ax.set_xticks([])
ax.set_ylim(ymin, ymax), ax.set_yticks([])
"""
if cmap == "tab10":
x = np.linspace(xmin, xmax, 11, endpoint=True) + 0.5*(xmax-xmin)/11
for i in range(10):
ax.text(x[i], (ymin+ymax)/2, "C%d"%i, color="white", zorder=10,
family = "Source Pro Serif", size=10, ha="center", va="center")
if cmap == "Greys":
x = np.linspace(xmin, xmax, 12, endpoint=True) + 0.5*(xmax-xmin)/12
for i in range(11):
color = "%.1f"%(i/10)
text = "%.1f"%(1-i/10)
ax.text(x[i], (ymin+ymax)/2, text, color=color, zorder=10,
family = "Source Pro Serif", size=10, ha="center", va="center")
"""
fig.savefig(ROOT_DIR / f"figures/colormap-{cmap}.pdf")
ax.clear()