-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateGif.py
64 lines (49 loc) · 1.51 KB
/
createGif.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
"""
Python file to plot the results of tournaments; Python 2 or 3
"""
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
def gather_data():
xs = []
ys = []
tempX = []
tempY = []
with open('geneticRes.txt', 'r') as fromFile:
for line in fromFile:
if line != '-------\n':
l = line.strip().split(' ')
tempX.append(l[0])
tempY.append(l[1])
else:
xs.append(tempX)
ys.append(tempY)
tempX = []
tempY = []
return xs, ys
def update(i):
global xs
global ys
xbar = reduce((lambda a, b: a + b),
map(lambda x: float(x), xs[i])) / len(xs[i])
ybar = reduce((lambda a, b: a + b),
map(lambda y: float(y), ys[i])) / len(ys[i])
print(xbar)
ax.scatter(xs[i], ys[i], s=1)
ax.scatter(xbar, ybar, color='blue')
if __name__ == '__main__':
xs, ys = gather_data()
fig, ax = plt.subplots()
fig.set_tight_layout(True)
# plt.axis('off')
# plt.title('Genetic Evaluation')
plt.xlabel('Weights')
plt.ylabel('Tournament Scores')
ax.set_yticklabels([])
ax.set_xticklabels([])
plt.xlim(0, 1)
print 'Number of points:', len(ys)
anim = FuncAnimation(fig, update, frames=np.arange(
0, len(ys)), interval=20, repeat_delay=0)
anim.save('linen.gif', dpi=120, writer='imagemagick')
print('doneeroo: output file is linen.gif')