I cannot see the edge information when I hover over the edge, but I can see the node information. Here is the code I am using, and the graph generated for reference.
res = [((‘pytorch’, ‘tensorflow’), 11446), ((‘arrow’, ‘pandas’), 8148), ((‘pandas’, ‘pytorch’), 2299), ((‘pytorch’, ‘tinygrad’), 1040), ((‘tensorflow’, ‘tinygrad’), 282), ((‘arrow’, ‘pytorch’), 795), ((‘numpy’, ‘pandas’), 16848), ((‘pandas’, ‘tensorflow’), 1237)]
import plotly.graph_objects as go
# Create a graph and add weighted edges
g = nx.Graph()
g.add_weighted_edges_from(res)
# Get positions for all nodes
pos = nx.spring_layout(g)
# Draw the nodes with sizes based on their degree
node_sizes = [nx.degree(g, n) for n in g.nodes()]
# Extract the x and y coordinates of the nodes
x_nodes = [pos[node][0] for node in g.nodes()]
y_nodes = [pos[node][1] for node in g.nodes()]
# Create the Plotly figure
fig = go.Figure()
# Add each edge as a separate scatter plot with its specific width and hover info
for edge in g.edges(data=True):
x_edges = [pos[edge[0]][0], pos[edge[1]][0], None]
y_edges = [pos[edge[0]][1], pos[edge[1]][1], None]
fig.add_trace(go.Scatter(
x=x_edges, y=y_edges,
mode='lines',
line=dict(width=edge[2]['weight'] / 1000, color='grey'),
hoverinfo='text',
text=f'Shared contributors: {edge[2]["weight"]}',
showlegend=False
))
# Add the nodes as a scatter plot
fig.add_trace(go.Scatter(
x=x_nodes, y=y_nodes,
mode='markers',
text=[str(node) for node in g.nodes()],
marker=dict(size=[size * 5 for size in node_sizes], color='skyblue', line=dict(color='black', width=1)),
textposition='top center',
textfont=dict(size=14),
hoverinfo='text'
))
# Add annotations for the node labels
annotations = []
for node, (x, y) in pos.items():
annotations.append(
dict(
x=x, y=y,
text=str(node),
showarrow=False,
xanchor='center',
yanchor='top',
font=dict(color='black', size=12),
bgcolor='white',
bordercolor='black',
borderwidth=1,
opacity=1.0 # Solid white background
)
)
# Update the layout to include annotations
fig.update_layout(
showlegend=False, # Disable legend for edges
annotations=annotations,
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
plot_bgcolor='white',
title='Repositories Network with Shared Contributors'
)
# Show the figure
fig.show()