Hi everyone. Right now Iâm creating a visualization of collaborations between some musicians. The goal is to show musiciansâ name and their work(collaborated song) beside edges. But I canât do the later part, it doesnât show in the place I want. I thought it should be displayed between two nodes.
labels are musiciansâ names and labels1 are song name that i want to display.
How can I fix this? Below are my source code.
Thank you.
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import platform
import networkx as nx
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot
init_notebook_mode(connected=True)
G=nx.Graph()# G is an empty Graph
my_nodes=range(10)
G.add_nodes_from(my_nodes)
my_edges=[(0,1), (0,2), (0,9), (1,3), (1,5), (2,4), (2, 7), (2, 8), (3,4),(4,5), (5, 6), (7,8),(8,7), (8,9)]
G.add_edges_from(my_edges)
G.add_edge(6,7)
pos=nx.fruchterman_reingold_layout(G)
labels=[âJustin Biberâ, âDJ Snakeâ,âDavid Guettaâ, âMĂâ, âAviciiâ, âSkrillexâ, âEllie Gouldingâ, âCalvin Harrisâ, âRihannaâ, âDrakeâ]
Xn=[pos[k][0] for k in range(len(pos))]
Yn=[pos[k][1] for k in range(len(pos))]
trace_nodes=dict(type=âscatterâ,
x=Xn,
y=Yn,
mode=âmarkers + textâ,
marker=dict(size=14, color=ârgb(0,240,0)â),
text=labels,
hoverinfo=âtextâ)
Xe=[]
Ye=[]
for e in G.edges():
Xe.extend([pos[e[0]][0], pos[e[1]][0], None])
Ye.extend([pos[e[0]][1], pos[e[1]][1], None])
labels1 = [âxxxxxxxxxxxxxxxxxxxâ, âaaaaaaaaaaaaaaaaaaaâ, âText Iâ,âText Gâ, âText Hâ, âText Iâ,âText Gâ, âText Hâ, âText Iâ,âText Gâ, âText Hâ, âText Iâ,âText Gâ, âText Hâ, âText Iâ]
trace_edges=dict(type=âscatterâ,
mode=âlines+textâ,
text=labels1,
x=Xe,
y=Ye,
line=dict(width=1, color=ârgb(25,25,25)â),
hoverinfo=âtextâ,
textposition=âbottom centerâ
)
print(len(G.edges()))
axis=dict(showline=False, # hide axis line, grid, ticklabels and title
zeroline=False,
showgrid=False,
showticklabels=False,
title=ââ
)
layout=dict(title= âMy Graphâ,
font= dict(family=âBaltoâ),
width=800,
height=800,
autosize=True,
showlegend=False,
xaxis=axis,
yaxis=axis,
margin=dict(
l=40,
r=40,
b=85,
t=100,
pad=0,
),
hovermode='closest',
plot_bgcolor='#efecea', #set background color
)
fig = dict(data=[trace_edges, trace_nodes], layout=layout)
#iplot(fig)
fig[âlayoutâ].update(annotations=make_annotations(pos, labels))
iplot(fig)
it shows like this right now