-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.py
46 lines (33 loc) · 1.07 KB
/
create.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
"""
Regenerate all those useful files that contain the color cycle.
"""
import matplotlib as mpl
import pylab as plt
# A list of (filename, template) pairs.
templates = [
('rg_friendly.mplstyle',
"""axes.prop_cycle : cycler('color', {string_list})
"""),
('rg_friendly.py',
"""
import matplotlib as mpl
from cycler import cycler
mpl.rcParams['axes.prop_cycle'] = cycler(color={hashstring_list})
"""),
]
cvals, names = zip(*[x.split() for x in open('colors.txt')])
data = {'string_list': '[' + ','.join(["'%s'" % c for c in cvals]) + ']',
'hashstring_list': '[' + ','.join(["'#%s'" % c for c in cvals]) + ']'}
# Make files...
for filename, template in templates:
open(filename, 'w').write(template.format(**data))
# Also make an image showing the colors with their names.
fig = plt.figure(figsize=(5, 4))
ax = plt.axes([0,0,1,1])
x = plt.arange(0., 6.28, .01)
y = plt.sin(x)
for i in range(len(names)):
ax.plot(x, y-i*2, lw=2, color='C{}'.format(i))
ax.text(1, 1-i*2, 'C{}: {}'.format(i, names[i]))
ax.axis('off')
fig.savefig('rg_friendly.png')