-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_data.py
67 lines (48 loc) · 1.55 KB
/
plot_data.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
import matplotlib.pyplot as plt
import random # for color generation
def parse_data_into_points(filename, scan_num=True):
with open(filename, "r") as fin:
data = fin.readlines()
lines = []
cur_line = list()
if scan_num: data = data[2:]
for d in data:
d = d.strip()
if d == "":
lines.append(cur_line)
cur_line = list()
else:
d = d.split(",")
cur_line.append((float(d[0]), float(d[1])))
if cur_line:
lines.append(cur_line)
return lines
def plot_lines(lines):
for line in lines:
color = (random.randint(0, 255) / 255, random.randint(0, 255) / 255, random.randint(0, 255) / 255, 1)
x = []
y = []
for point in line:
x.append(point[0])
y.append(point[1])
plt.plot(x, y, color=color)
def plot_nice_picture(lines, result, line_file="", result_file=""):
plt.figure(figsize=(5, 4))
plt.title("Upper envelope")
if line_file:
lines = parse_data_into_points(line_file)
if result_file:
result = parse_data_into_points(result_file, scan_num=False)[0]
plot_lines(lines)
x = []
y = []
for point in result:
try:
x.append(point.x)
y.append(point.y)
except:
x.append(point[0])
y.append(point[1])
plt.plot(x, y, color="red")
plt.scatter(x, y, color="red")
plt.show()