-
Notifications
You must be signed in to change notification settings - Fork 16
/
visualize.py
executable file
·48 lines (30 loc) · 954 Bytes
/
visualize.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
#!/usr/bin/python
import matplotlib.pyplot as plt
import networkx as nx
import csv
def save_graph(graph,file_name):
#initialze Figure
plt.figure(num=None, figsize=(20, 20), dpi=80)
plt.axis('off')
fig = plt.figure(1)
pos = nx.spring_layout(graph)
nx.draw(graph,pos)
plt.draw()
plt.show()
def calculate_degree_centrality(g):
dc = nx.degree_centrality(g)
nx.set_node_attributes(g,'degree_cent',dc)
degcent_sorted = sorted(dc.items(), reverse=True)
for key, value in degcent_sorted[0:10] :
print "Highest degree Centrality:",key,value
return dc
def main():
G=nx.DiGraph()
with open('./userdata/edges.csv', 'Ur') as f:
edges = list(tuple(rec) for rec in csv.reader(f, delimiter=','))
for edge in edges[1:200]:
G.add_edge(*edge)
calculate_degree_centrality(G)
save_graph(G,'graph.pdf')
if __name__ == '__main__':
main ()