-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlive_plot.py
More file actions
49 lines (43 loc) · 1.22 KB
/
live_plot.py
File metadata and controls
49 lines (43 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
#Copyright @ Somdip Dey, 2018
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import time
# Style of plot
style_name = 'dark_background'
style.use(style_name)
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def main():
plt.rcParams['agg.path.chunksize'] = 10000
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
def animate(i):
graph_data = open(file_name,'r').read()
lines = graph_data.split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 1:
x, y = line.split(',')
xs.append(float(x))
ys.append(float(y))
ax1.clear()
ax1.plot(xs, ys)
if __name__ == '__main__':
import sys
import os.path
args = False
try:
args = sys.argv[1]
except IndexError:
args = False
if(args != False):
file_name = str(args)
is_file = os.path.isfile(file_name)
if is_file == False:
print('\nError::\n\nWrong file selected! Please, check the path and file name again.\n')
sys.exit(1)
main()
else:
print('\nError::\n\nNo file selected to read X,Y for plotting!\nPlease, select a file first.\n')