-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPySVGPalette.py
192 lines (146 loc) · 4.71 KB
/
PySVGPalette.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import colorsys
import numpy as np
import seaborn as sns
from matplotlib import patches
import matplotlib.colors as mcl
import matplotlib.pyplot as plt
plt.switch_backend('TkAgg')
def mplrgb_to_rgb(a):
return np.array(a) * 255.
def mplhls_to_hls(a):
return (a[0] * 360, a[1] * 100, a[2] * 100)
def display_palette(p):
a = []
print 'RGB\t HLS'
for p in palette:
print mcl.rgb2hex(p),
print ['{:.2f}'.format(cc) for cc in mplrgb_to_rgb(p)],
print ['{:.2f}'.format(cc) for cc in mplhls_to_hls(colorsys.rgb_to_hls(*p))]
# print ['{:1.2f}'.format(cc * hls_scale[i])
# for i, cc in enumerate(mcl.rgb_to_hsv(p))]
a.append(
mplhls_to_hls(colorsys.rgb_to_hls(*p)))
sns.palplot(palette)
return a
# ======================================================================
# COLOR SCHEMER
# ======================================================================
beigetone = np.array([
(176, 102, 96),
(202, 143, 66),
(171, 156, 115),
(94, 119, 3),
(106, 125, 142)])
earthtone = np.array([
(73, 56, 41),
(97, 51, 25),
(213, 117, 0),
(64, 79, 36),
(78, 97, 114),
(43, 43, 43)])
bgcolor = colorsys.hls_to_rgb(90/360., 15/16., 0/16.)
palette = earthtone/255.
hexcolor = mcl.rgb2hex(bgcolor)
# HSL
n_colors = 32.
print "Angle step: {:g}".format(360/n_colors)
palette_base = sns.hls_palette(n_colors, h=0, l=15/16., s=1/16.)
palette_base = sns.hls_palette(n_colors, h=0, l=3/16., s=12/16.)
fig, (ax) = plt.subplots(1, figsize=(1920/120., 1080/120.), tight_layout=False)
print (fig.get_figwidth(), fig.get_figheight())
fig.suptitle("{:s} - {:s}".format(
hexcolor, str(np.array(mcl.hex2color(hexcolor))*255)), fontsize=20)
# fig.patch.set_facecolor(palette[-1])
ax.set_axis_bgcolor(earthtone[3]/255.)
ax.set_aspect('equal')
ax.set_xlim(0, n_colors)
ax.set_ylim(0, n_colors)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
# ax.set_axis_off()
for i, cc in enumerate(palette):
ax.add_patch(
patches.Rectangle((i*4, 0), 4, 4, color=cc))
for i, cc in enumerate(palette_base):
ax.add_patch(
patches.Rectangle((i*1, 22), 1, 2, color=cc, ec=palette[-1], lw=1))
ax.text(i*1 + .1, 23, '{:g}'.format(i*360/n_colors), color=palette[-1])
plt.show()
wurstel
# palette = sns.hls_palette(12, l=.5, s=.5)
# palette = sns.husl_palette(5, h=.05)
# a = display_palette(palette)
palette = [
colorsys.hls_to_rgb(i*15/360., 0.5, 1)
for i in range(24)]
print palette
sns.palplot(palette)
palette = sns.hls_palette(24, h=0, l=.5, s=1)
print palette
sns.palplot(palette)
palette = rgb_to_mplrgb(RGB)
b = display_palette(palette)
# fig, (ax1) = plt.subplots(1, figsize=(16, 9))
# ax1.plot(a, '-o')
# ax1.plot(b, '--o')
# ax1.legend(['h', 'l', 's', 'h', 'l', 's'])
plt.show()
wurstel
# ======================================================================
# ======================================================================
n = 300
theta = np.linspace(0, 2 * np.pi, n)
x = np.cos(theta)
y = np.sin(theta)
f = plt.figure(figsize=(10, 5))
with sns.color_palette("husl", n):
ax = f.add_subplot(121)
ax.plot([np.zeros_like(x), x], [np.zeros_like(y), y], lw=3)
ax.set_axis_off()
ax.set_title("HUSL space")
with sns.color_palette("hls", n):
ax = f.add_subplot(122)
ax.plot([np.zeros_like(x), x], [np.zeros_like(y), y], lw=3)
ax.set_axis_off()
ax.set_title("HLS space")
f.tight_layout()
cblue = (0/255., 83/255., 161/255.)
rgb_scale = (255, 255, 255)
hls_scale = (360, 100, 100)
print '\n--> HLS'
palette = sns.color_palette("hls", 12) + [cblue]
palette = sns.hls_palette(12, l=.5, s=.5)
print 'RGB\t HLS'
for p in palette:
print mcl.rgb2hex(p),
print ['{:03.2f}'.format(cc * rgb_scale[i])
for i, cc in enumerate(p)],
print ['{:03.2f}'.format(cc * hls_scale[i])
for i, cc in enumerate(colorsys.rgb_to_hls(*p))]
# print ['{:1.2f}'.format(cc * hls_scale[i])
# for i, cc in enumerate(mcl.rgb_to_hsv(p))]
sns.palplot(palette)
# In[3]:
print '\n\n--> HUSL'
palette = sns.color_palette("husl", 12) + [cblue]
palette = sns.husl_palette(12, s=.5, l=.5)
print 'RGB\t HLS'
for p in palette:
print mcl.rgb2hex(p),
print ['{:03.2f}'.format(cc * rgb_scale[i])
for i, cc in enumerate(p)],
print ['{:03.2f}'.format(cc * hls_scale[i])
for i, cc in enumerate(colorsys.rgb_to_hls(*p))]
# print ['{:1.2f}'.format(cc * hls_scale[i])
# for i, cc in enumerate(mcl.rgb_to_hsv(p))]
sns.palplot(palette)
sns.husl_palette
plt.show()
wurstel
# In[4]:
sns.color_palette("hls", 8)
sns.palplot(sns.color_palette("hls", 8))
# In[5]:
sns.set(rc={"figure.figsize": (6, 6)})
np.random.seed(sum(map(ord, "palettes")))
plt.show()