forked from tfiers/kul-machine-learning-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_vis.py
44 lines (28 loc) · 930 Bytes
/
graph_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
from url_predictor import learn_from
import matplotlib.pyplot as plt
import networkx as nx
def visualise(csv_file):
G = nx.Graph()
nodes = learn_from(open(csv_file))
domain_list = []
for node in nodes:
G.add_node(node)
domain = nodes[node]['domain']
if domain not in domain_list:
domain_list.append(domain)
G.node[node]['domain'] = domain
links = nodes[node]['direct_links']
for link in links:
G.add_edge(node,link)
color_map = get_color_map(domain_list)
print(str(color_map))
nx.draw(G, node_color=[color_map[G.node[node]['domain']] for node in G]) #label = [G.node[node]['domain'] for node in G] )
#plt.legend()
plt.show()
def get_color_map(list):
color_table = ['#ff0000','#ff8000','#ffff00','#80ff00','#00ffbf','#00bfff','#0040ff','#8000ff','#bf00ff','#ff00ff']
color_map = dict()
for i in range(len(list)):
pos = i % 10
color_map[list[i]] = color_table[i]
return color_map