SHARE
TWEET

Untitled

a guest Mar 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import plotly.plotly as py
  2. import plotly.graph_objs as go
  3. from plotly.offline import init_notebook_mode, iplot
  4. init_notebook_mode(connected=True)
  5.  
  6. layt = nx.kamada_kawai_layout(G, dim=3)
  7.  
  8. Xn=[layt[k][0] for k in heroes_names] # x-coordinates of nodes
  9. Yn=[layt[k][1] for k in heroes_names] # y-coordinates
  10. Zn=[layt[k][2] for k in heroes_names] # z-coordinates
  11. Xe=[]
  12. Ye=[]
  13. Ze=[]
  14. for e in G.edges:
  15.     Xe+=[layt[e[0]][0],layt[e[1]][0], None] # x-coordinates of edge ends
  16.     Ye+=[layt[e[0]][1],layt[e[1]][1], None]  
  17.     Ze+=[layt[e[0]][2],layt[e[1]][2], None]
  18.  
  19.  
  20. trace1=go.Scatter3d(x=Xe,
  21.                     y=Ye,
  22.                     z=Ze,
  23.                     mode='lines',
  24.                     line=dict(color=colors, width=0.2, colorscale='Viridis',),
  25.                     hoverinfo='text',
  26.                     text=[G[u][v]['weight'] for u, v in edges],
  27.                    )
  28.  
  29. trace2=go.Scatter3d(x=Xn,
  30.                y=Yn,
  31.                z=Zn,
  32.                mode='markers+text',
  33.                name='heroes',
  34.                marker=dict(symbol='circle',
  35.                              size=10,
  36.                              color=node_color_popul,
  37.                              colorscale='Viridis',
  38.                                 colorbar=dict(title='Node weight'),
  39.                              line=dict(color='rgb(50,50,50)', width=1)
  40.                              ),
  41.                text=[x+' ' + str(count_heroes[x]) for x in G.nodes],# labels,
  42.                hoverinfo='text'
  43.                )
  44.  
  45. axis=dict(showbackground=False,
  46.           showline=False,
  47.           zeroline=False,
  48.           showgrid=False,
  49.           showticklabels=False,
  50.           title=''
  51.           )
  52.  
  53. layout = go.Layout(
  54.          title="Network of coappearances of heroes",
  55.          width=1000,
  56.          height=1000,
  57.          showlegend=False,
  58.          scene=dict(
  59.              xaxis=dict(axis),
  60.              yaxis=dict(axis),
  61.              zaxis=dict(axis),
  62.         ),
  63.      margin=dict(
  64.         t=100
  65.     ),
  66.     hovermode='closest',  
  67. )
  68.  
  69. data=[trace1, trace2]
  70. fig=go.Figure(data=data, layout=layout)
  71.  
  72. iplot(fig)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top