Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import plotly.plotly as py
- import plotly.graph_objs as go
- from plotly.offline import init_notebook_mode, iplot
- init_notebook_mode(connected=True)
- layt = nx.kamada_kawai_layout(G, dim=3)
- Xn=[layt[k][0] for k in heroes_names] # x-coordinates of nodes
- Yn=[layt[k][1] for k in heroes_names] # y-coordinates
- Zn=[layt[k][2] for k in heroes_names] # z-coordinates
- Xe=[]
- Ye=[]
- Ze=[]
- for e in G.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]
- trace1=go.Scatter3d(x=Xe,
- y=Ye,
- z=Ze,
- mode='lines',
- line=dict(color=colors, width=0.2, colorscale='Viridis',),
- hoverinfo='text',
- text=[G[u][v]['weight'] for u, v in edges],
- )
- trace2=go.Scatter3d(x=Xn,
- y=Yn,
- z=Zn,
- mode='markers+text',
- name='heroes',
- marker=dict(symbol='circle',
- size=10,
- color=node_color_popul,
- colorscale='Viridis',
- colorbar=dict(title='Node weight'),
- line=dict(color='rgb(50,50,50)', width=1)
- ),
- text=[x+' ' + str(count_heroes[x]) for x in G.nodes],# labels,
- hoverinfo='text'
- )
- axis=dict(showbackground=False,
- showline=False,
- zeroline=False,
- showgrid=False,
- showticklabels=False,
- title=''
- )
- layout = go.Layout(
- title="Network of coappearances of heroes",
- width=1000,
- height=1000,
- showlegend=False,
- scene=dict(
- xaxis=dict(axis),
- yaxis=dict(axis),
- zaxis=dict(axis),
- ),
- margin=dict(
- t=100
- ),
- hovermode='closest',
- )
- data=[trace1, trace2]
- fig=go.Figure(data=data, layout=layout)
- iplot(fig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement