-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphSims.py
53 lines (41 loc) · 1.43 KB
/
graphSims.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
__author__ = 'thomas'
import os
import networkx as nx
import matplotlib.pyplot as plt
import pickle
threshold = 0.98
pickleFile = os.path.join(os.getcwd(), "cache/sims/sims.cos")
simsList = pickle.load(open(pickleFile, "rb"))
G = nx.Graph()
weights = []
for fileid1, fileid2, sim in simsList:
if sim > threshold:
G.add_edge(fileid1, fileid2, weight=sim)
else:
break
# e1 = [(u, v) for (u, v, d) in G.edges(data=True) if d['weight'] <= 0.2]
# e2 = [(u, v) for (u, v, d) in G.edges(data=True) if 0.2 < d['weight'] <= 0.4]
# e3 = [(u, v) for (u, v, d) in G.edges(data=True) if 0.4 < d['weight'] <= 0.6]
# e4 = [(u, v) for (u, v, d) in G.edges(data=True) if 0.6 < d['weight'] <= 0.8]
# e5 = [(u, v) for (u, v, d) in G.edges(data=True) if 0.8 < d['weight'] <= 1.0]
# pos = nx.circular_layout(G, scale=10.0) # positions for all nodes
#
# # nodes
# nx.draw_networkx_nodes(G, pos)
#
# # edges
# nx.draw_networkx_edges(G, pos, edgelist=e1, width=1)
# nx.draw_networkx_edges(G, pos, edgelist=e2, width=1)
# nx.draw_networkx_edges(G, pos, edgelist=e3, width=1)
# nx.draw_networkx_edges(G, pos, edgelist=e4, width=1)
# nx.draw_networkx_edges(G, pos, edgelist=e5, width=1)
nx.draw_networkx(G)
#nx.draw_networkx_labels(G, pos, font_size=10, font_family='sans-serif')
plt.axis('off')
# plt.savefig("weighted_graph.png") # save as png
plt.show() # display
print("done")
#nx.draw(g)
#nx.draw_random(g)
#nx.draw_circular(g)
#nx.draw_spectral(g)