This repository has been archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvis.py
61 lines (45 loc) · 1.48 KB
/
vis.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
import matplotlib.pyplot as plt
import sys
def reading(filename):
vals = [[], []]
with open(filename, 'r') as f:
labels = f.readline().split(',')
labels[-1] = labels[-1].replace('\n', '')
for line in f:
spl_line = line.split(',')
vals[0].append(float(spl_line[0]))
vals[1].append(float(spl_line[1]))
return vals, labels
def draw_2d(data_filename, result_filename, result_knots_filename):
vals, labels = reading(data_filename)
plt.plot(vals[0], vals[1], 'r.', label='data')
vals, labels = reading(result_filename)
plt.plot(vals[0], vals[1], 'b', label='spline')
vals, labels = reading(result_knots_filename)
plt.plot(vals[0], vals[1], 'gs', label='knots')
plt.title('Approximation of spline')
plt.xlabel('X', fontsize=12)
plt.ylabel('Y', fontsize=12)
plt.grid()
plt.legend()
plt.show()
def main():
try:
dim = int(sys.argv[1])
data_filename = sys.argv[2]
result_filename = sys.argv[3]
result_knots_filename = sys.argv[4]
except IndexError:
print("Args: <dimension> <data filename> <result filename> <result knots filename>")
return
except ValueError:
print("Dimension should be int")
return
else:
if dim == 2:
draw_2d(data_filename, result_filename, result_knots_filename)
elif dim == 3:
pass
else:
print("Dimension should be 2 or 3")
main()