-
Notifications
You must be signed in to change notification settings - Fork 0
/
live_visu.py
66 lines (51 loc) · 1.25 KB
/
live_visu.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
#!/usr/bin/env python
#
# Copyright (c) 2013-2016, ETH Zurich.
# All rights reserved.
#
# This file is distributed under the terms in the attached LICENSE file.
# If you do not find this file, copies can be found by writing to:
# ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
import networkx as nx
import matplotlib.pyplot as plt
import pylab
import re
import fileinput
G = nx.DiGraph()
def output(l):
"""
Parse output line
"""
global G
print l.rstrip()
if re.match('^NODE: \d+', l):
v = l.split()
n = int(v[1])
G.add_node(n);
print 'adding node %d' % n
return True
elif re.match('^EDGE: \d+ -> \d+', l):
(_, n1, _, n2) = l.split()
n1 = int(n1)
n2 = int(n2)
G.add_edge(n1, n2)
print 'adding edge %d -> %d' % (n1, n2)
return True
return False
def draw_loop():
"""
Draw the graph in a loop
"""
global G
plt.ion()
# mng = plt.get_current_fig_manager()
# mng.resize(*mng.window.maxsize())
plt.draw()
for line in fileinput.input():
if output(line):
plt.clf()
nx.draw(G)
plt.draw()
print "Enabling interactive mode"
pylab.ion()
draw_loop()