-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_emst.py
41 lines (36 loc) · 1.09 KB
/
plot_emst.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
import matplotlib.pyplot as plt
import sys
import subprocess
def get_color(x):
l = plt.rcParams['axes.prop_cycle'].by_key()['color']
return l[x % len(l)]
def main():
file_name = sys.argv[1]
output = subprocess.check_output(
['./emst_main.exe', file_name]
).decode('utf-8')
lines = output.split('\n')
num_nets = int(lines[0])
cur = 1
plt.figure('EMST')
plt.ylim([0, 9])
for net in range( num_nets ):
num_vertices = int(lines[cur])
cur += 1
vertices = []
for i in range( num_vertices ):
vertices.append(
list(map(int, lines[cur + i].split()))
)
plt.scatter(*vertices[-1], color = get_color(net))
cur += num_vertices
for i in range( num_vertices - 1):
line = list(map(int, lines[cur + i].split()))
plt.plot([vertices[line[0]][0], vertices[line[1]][0]],
[vertices[line[0]][1], vertices[line[1]][1]],
color = get_color(net)
)
cur += num_vertices - 1
plt.show()
if __name__ == '__main__':
main()