- Notifications
You must be signed in to change notification settings - Fork 908
/
Copy pathcolornames.py
59 lines (43 loc) · 1.4 KB
/
colornames.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
"""
========================
Visualizing named colors
========================
Simple plot example with the named colors and its visual representation.
"""
importpathlib
importmatplotlibasmpl
importmatplotlib.pyplotasplt
ROOT_DIR=pathlib.Path(__file__).parent.parent
mpl.style.use([
ROOT_DIR/'styles/base.mplstyle',
])
mpl.rc('figure.constrained_layout', h_pad=0, w_pad=0, hspace=0, wspace=0)
colors=dict(mpl.colors.BASE_COLORS, **mpl.colors.CSS4_COLORS)
# Sort colors by hue, saturation, value and name.
by_hsv=sorted((tuple(mpl.colors.rgb_to_hsv(mpl.colors.to_rgba(color)[:3])), name)
forname, colorincolors.items())
sorted_names= [nameforhsv, nameinby_hsv]
n=len(sorted_names)
ncols=3
nrows=n//ncols
fig, ax=plt.subplots(figsize=(4.5, 6))
# Get height and width
X, Y=fig.get_dpi() *fig.get_size_inches()
h=Y/ (nrows+1)
w=X/ncols
fori, nameinenumerate(sorted_names):
col=i//nrows
row=i%nrows
y=Y- (row*h) -h
xi_line=w* (col+0.05)
xf_line=w* (col+0.25)
xi_text=w* (col+0.3)
ax.text(xi_text, y, name, fontsize=7,
horizontalalignment='left',
verticalalignment='center')
ax.hlines(y+h*0.1, xi_line, xf_line,
color=colors[name], linewidth=(h*0.6))
ax.set_xlim(0, X)
ax.set_ylim(0, Y)
ax.set_axis_off()
fig.savefig(ROOT_DIR/"figures/colornames.pdf")