forked from nikhgarg/scholar.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualization.py
45 lines (40 loc) · 1.12 KB
/
Visualization.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
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 14 23:31:24 2014
@author: Nikhil
"""
import networkx as nx
import matplotlib.pyplot as plt
import csv
def test():
G=nx.DiGraph()
G.add_nodes_from([124234,223423,3234234, 1, 2, 3, 3])
G.add_edges_from([(1,2),(1,3),(2,1)])
print G.nodes()
print G.edges()
nx.draw_networkx(G)
plt.show()
def visualizeGraph(graphFileName):
with open(graphFileName, 'r') as graph:
G=nx.DiGraph()
graphreader = csv.reader(graph, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
for row in graphreader:
intRow = []
for x in row:
if x.isdigit():
intRow.append(int(x))
G.add_nodes_from(intRow)
if len(intRow)>1:
for x in intRow[1:]:
G.add_edge(intRow[0], x)
print G.nodes()
print G.edges()
nx.draw_circular(G)
plt.show()
nx.draw_spring(G)
plt.show()
nx.draw_networkx(G)
plt.show()
visualizeGraph('graph_4.csv')
print 'done'