-
Notifications
You must be signed in to change notification settings - Fork 906
/
Copy pathcolors.py
49 lines (40 loc) · 1.71 KB
/
colors.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
# -----------------------------------------------------------------------------
# Matplotlib cheat sheet
# Released under the BSD License
# -----------------------------------------------------------------------------
import sys
import pathlib
import numpy as np
import matplotlib as mpl
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]
ax.set_xlim(xmin, xmax), ax.set_xticks([])
ax.set_ylim(ymin, ymax), ax.set_yticks([])
# Uniform colormaps
# -----------------------------------------------------------------------------
palettes = {
'raw' : ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'],
'rgba' : [(1, 0, 0), (1, 0, 0, 0.75), (1, 0, 0, 0.50), (1, 0, 0, 0.25)],
'HexRGBA' : ["#FF0000", "#FF0000BB", "#FF000088", "#FF000044"],
'cycle' : ["C%d" % i for i in range(10)],
'grey' : ["%1.1f" % (i/10) for i in range(11)],
'name' : ["DarkRed", "Firebrick", "Crimson", "IndianRed", "Salmon" ] }
for name, colors in palettes.items():
C = mpl.colors.to_rgba_array(colors).reshape((1, len(colors), 4))
ax.imshow(C, extent=[xmin, xmax, ymin, ymax])
dx = (xmax-xmin)/len(colors)
for i in range(len(colors)):
color = "white"
if colors[i] in ['1.0', 'w']: color = "black"
text = str(colors[i]).replace(' ', '')
ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=color, zorder=10,
family="Source Code Pro", size=9, ha="center", va="center")
fig.savefig(ROOT_DIR / f"figures/colors-{name}.pdf")
ax.clear()