-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
executable file
·55 lines (43 loc) · 1.2 KB
/
graph.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
#!python3
import time
import threading
import matplotlib.pyplot as plt
from argparse import ArgumentParser
lgd = []
data = []
parser = ArgumentParser(
prog="graph.py",
description="Generate animated graph of incoming csv data"
)
parser.add_argument("--timedelay", "-t", default=0.1, type=float)
args = parser.parse_args()
def main():
thread1 = threading.Thread(target=input_thread, name="Input thread")
thread2 = threading.Thread(
target=plot_thread, name="Plot thread", daemon=True)
thread1.start()
thread2.start()
def input_thread():
global lgd
lgd = [x for x in input().strip(",").split(',')]
for _ in range(len(lgd)):
data.append([])
while True:
line = [float(x) for x in input().strip(",").split(',')]
for i in range(len(line)):
data[i].append(line[i])
def plot_thread():
plt.ion()
plt.style.use("seaborn")
fig = plt.figure()
plt.legend()
while True:
for i in range(len(lgd)):
plt.plot(data[i], linewidth=1, label=lgd[i])
plt.legend()
plt.draw()
time.sleep(args.timedelay)
fig.canvas.flush_events()
plt.clf()
if __name__ == "__main__":
main()