-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive-data.py
More file actions
79 lines (41 loc) · 1.22 KB
/
Copy pathlive-data.py
File metadata and controls
79 lines (41 loc) · 1.22 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# run 1 followed by other
#script 1
import pandas as pd
x_value=0
chan1=1000
chan2=1000
fieldnames=['x_value','chan1','chan2']
with open('D:/projects/env_site/realtime-data.csv','w') as csv_file:
csv_writer=csv.DictWriter(csv_file,fieldnames=fieldnames)
csv_writer.writeheader()
while True:
with open('D:/projects/env_site/realtime-data.csv','a') as csv_file:
csv_writer=csv.DictWriter(csv_file,fieldnames=fieldnames)
info={
'x_value':x_value,
'chan1':chan1,
'chan2':chan2
}
csv_writer.writerow(info)
x_value+=1
chan1=chan1+ random.randint(-6,8)
chan2=chan2+ random.randint(-4,7)
time.sleep(0.2)
#scipt 2
from itertools import count
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
x=[]
y=[]
index=count()
def animate(i):
data=pd.read_csv('realtime-data.csv')
x=data['x_value']
y=data['chan1']
z=data['chan2']
plt.cla()
plt.plot(x,y)
plt.plot(x,z)
ani=FuncAnimation(plt.gcf(),animate,interval=1000)
plt.show()