-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotting_from_file.py
68 lines (56 loc) · 1.9 KB
/
plotting_from_file.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
65
66
67
68
# https://pythonprogramming.net/python-matplotlib-live-updating-graphs/
# Plots data text files as it gets updated
# Run this in a separate terminal window as the simulator is running
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure(figsize=(8, 10))
#fig.tight_layout()
fig.set_tight_layout(True)
# ax1 = fig.add_subplot(1,2,2)
# ax2 = fig.add_subplot(1,2,1)
axes = {}
axes["wsize"] = fig.add_subplot(6,1,1)
axes["flowrate"] = fig.add_subplot(6,1,2)
# axes["delay"] = fig.add_subplot(6,1,3)
# axes["linkrate"] = fig.add_subplot(6,1,4)
# axes["dropped"] = fig.add_subplot(6,1,5)
# axes["buffocc"] = fig.add_subplot(6,1,6)
data = {}
data["wsize"] = [[], []]
data["flowrate"] = [[], []]
# data["delay"] = [[], []]
# data["linkrate"] = [[], []]
# data["dropped"] = [[], []]
# data["buffocc"] = [[], []]
gid = "0"
def animate(i):
for filename, ax in axes.items():
#ax.ylabel("packets")
#ax.xlabel('time (ms)')
path = "data/" + filename + gid + ".txt"
try:
f = open(path ,"r")
pullData = f.read()
dataArray = pullData.split('\n')
xar = data[filename][0]
yar = data[filename][1]
for eachLine in dataArray:
if len(eachLine)>1:
x,y = eachLine.split(',')
xar.append(float(x))
yar.append(float(y))
f.close()
open(path ,"w").close() # Clear text file
ax.clear()
ax.set_ylabel(filename)
ax.set_xlabel("time")
ax.plot(xar,yar)
except IOError as e:
continue
# Initial clearing
for filename, ax in axes.items():
path = "data/" + filename + gid + ".txt"
open(path ,"w").close() # Clear text file
ani = animation.FuncAnimation(fig, animate, interval=10)
#ani = animation.FuncAnimation(fig2, animate, interval=10)
plt.show()