-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_graph.py
37 lines (31 loc) · 928 Bytes
/
plot_graph.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
from igraph import *
import pickle
import random
#open links
with open('./all_links.pkl', 'rb') as f:
links = pickle.load(f)
#open ranks and create ranks list
ranks = {}
with open('./ranks2.txt', 'rb') as t:
for line in t:
splitLine = line.decode().split(':')
ranks[splitLine[0]] = float(splitLine[1])
#create dictionary of atrticles to numbers in alphabetical order
articles = {}
j = 0
for row in links:
articles[row['source']] = 0
articles[row['dest']] = 0
i = 0
for name in sorted(articles.keys()):
articles[name] = i
i += 1
n = len(articles)
#read the graph
g = Graph.Read_Pickle("graph.pkl")
#delete n-40 vertices randomly and plot
g.delete_vertices(random.sample(range(0, n), n - 40))
layout = g.layout("kk")
plot(g, layout=layout, bbox=(1080, 1360), margin=100,
vertex_size=[(100000 * ranks[name])
if (100000 * ranks[name]) > 10 else 10 for name in g.vs["label"]])