-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
91 lines (68 loc) · 2.16 KB
/
test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
from urllib.request import urlopen
import requests
import urllib.request
import igraph as ig
import chart_studio.plotly as py
from plotly.offline import iplot
import plotly.graph_objs as go
data = []
with urllib.request.urlopen("https://raw.githubusercontent.com/purplnecropanda/backrooms-test/main/backrooms.json") as response:
html = response.read()
data = json.loads(html)
print(data.keys())
N=len(data['nodes'])
print(N)
L=len(data['links'])
Edges=[(data['links'][k]['source'], data['links'][k]['target']) for k in range(L)]
G=ig.Graph(Edges, directed=False)
#print(N) #returns 77
print(data['nodes'][0]) #returns {‘name’: ‘Top-level’, ‘group’: 1}
#print(data.keys()) #returns dict_keys([‘nodes’, ‘links’])
G=ig.Graph(Edges, directed=False)
layt=G.layout('kk', dim=3) # plot network with the Kamada-Kawai layout algorithm
print(G)
print(layt[:3])
print(Edges[:3])
labels=[]
group=[]
for node in data['nodes']:
labels.append(node['name'])
group.append(node['group'])
print(labels[:3])
print(group[:3])
Xn=[]
Yn=[]
Zn=[]
for k in range(N):
Xn+=[layt[k][0]]
Yn+=[layt[k][1]]
Zn+=[layt[k][2]]
Xe=[]
Ye=[]
Ze=[]
for e in Edges:
Xe+=[layt[e[0]][0],layt[e[1]][0],None]# x-coordinates of edge ends
Ye+=[layt[e[0]][1],layt[e[1]][1],None]
Ze+=[layt[e[0]][2],layt[e[1]][2],None]
print(Xe[:3])
print(Ye[:3])
print(Ze[:3])
trace1=go.Scatter3d(x=Xe, y=Ye, z=Ze, mode='lines', line=dict(color='rgb(125,125,125)', width=1),hoverinfo='none')
trace2=go.Scatter3d(x=Xn, y=Yn, z=Zn, mode='markers', name='actors',
marker=dict(symbol='circle', size=6, color=group, colorscale='Viridis',
line=dict(color='rgb(50,50,50)', width=0.5)), text=labels, hoverinfo='text')
axis=dict(showbackground=False, showline=False, zeroline=False, showgrid=False, showticklabels=False, title='')
layout = go.Layout(
title="backrooms",
width=1000,
height=1000,
showlegend=False,
scene=dict(
xaxis=dict(axis),
yaxis=dict(axis),
zaxis=dict(axis),
))
data=[trace1, trace2]
fig=go.Figure(data=data, layout=layout)
iplot(fig, filename='Back-rooms')