-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotFile.py
45 lines (34 loc) · 923 Bytes
/
plotFile.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
import matplotlib.pyplot as plt
import os
file_name = "serial_input.txt"
delimiter = ','
def plotFile(file_name,delimiter):
inputFile = open(file_name,'r')
lines = inputFile.readlines()
x = list()
y = list()
n = 0
for line in lines:
l = line.strip()
values = l.split(delimiter)
if(len(l)>0):
if(len(values) == 2):
x.append(float(values[0]))
y.append(float(values[1]))
elif(len(values) == 1):
x.append(n)
y.append(float(values[0]))
n+=1
# plotting the data
plt.plot(x, y)
# Adding the title
plt.title(file_name + " Plot")
# Adding the labels
plt.ylabel("y-axis")
plt.xlabel("x-axis")
plt.show()
def plot():
global file_name,delimiter
plotFile(file_name,delimiter)
if __name__ == "__main__":
plotFile(file_name,delimiter)