-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot-progress.py
More file actions
56 lines (43 loc) · 1.43 KB
/
Copy pathplot-progress.py
File metadata and controls
56 lines (43 loc) · 1.43 KB
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
import os
import time
import argparse
import numpy as np
import matplotlib.pyplot as pl
def moving_average(x, w):
return np.convolve(x, np.ones(w), 'valid') / w
def main():
parser = argparse.ArgumentParser(description='Plot progress')
parser.add_argument('-f', type=str)
parser.add_argument('-n', type=int, default=None)
args = parser.parse_args()
if not os.path.isfile(args.f):
print("File {} doesn't exists!".format(args.f))
return
pl.ion()
fig = pl.figure()
ax = fig.add_subplot(111)
while True:
with open(args.f, 'r') as f:
data = f.read().split('\n')
labels = data[1].split(',')
data = data[2:]
data = [np.array(list(map(lambda x: float(x.strip()), filter(lambda t: t != '', data[i].split(','))))) for i in range(0, len(data))]
data = np.transpose(np.stack(np.array(data[:-1])))
n,m = data.shape
if args.n:
data = [moving_average(data[i], args.n) for i in range(0, n)]
data = np.stack(np.asarray(data))
n,m = data.shape
fig.canvas.flush_events()
ax.clear()
timeline = np.linspace(0,1, m)
for i in range(0, n):
ax.plot(timeline, data[i], label=labels[i])
ax.legend()
fig.canvas.draw()
time.sleep(1.0)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass