# Python networkx, plotly. How to display Edges mouse-over text

**URL:** <https://community.plotly.com/t/python-networkx-plotly-how-to-display-edges-mouse-over-text/70350>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [November 29, 2022, 11:44am UTC](https://community.plotly.com/t/python-networkx-plotly-how-to-display-edges-mouse-over-text/70350 "2022-11-29T11:44:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedi](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@Jedi](https://community.plotly.com/u/Jedi)\
**Post date:** [November 29, 2022, 11:44am UTC](https://community.plotly.com/t/python-networkx-plotly-how-to-display-edges-mouse-over-text/70350/1 "2022-11-29T11:44:01Z")

</div>

I need to display text when mouse is over edges (similar to image). Maybe someone knows how to do it? I took the example from [plotly.com](https://plotly.com/python/network-graphs/) and trying to modify it. It fine works for Nodes, but I can not do it for Edges.

 ![networkx_edge_mouseover](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/0/602b5391c3f350d83bf1c3c52b4bf5622e96be41.png)

```python
import networkx
import plotly.graph_objects as go

G = networkx.random_geometric_graph(n=3, radius=1)

# Create Edges
edge_x, edge_y = [], []
for idx0, idx1 in G.edges():
    x0, y0 = G.nodes[idx0]["pos"]
    x1, y1 = G.nodes[idx1]["pos"]
    edge_x.extend([x0, x1, None])
    edge_y.extend([y0, y1, None])

edge_trace = go.Scatter(
    x=edge_x, y=edge_y, line=dict(width=10, color='#888'), mode='lines',
    hoverinfo='text', # TODO, NOT WORKING
)
# TODO, NOT WORKING
edge_trace.text = [f"# {s}" for s in edge_x]

# Create Nodes with TEXT
node_x = []
node_y = []
nodes_o = G.nodes
nodes_ids = list(nodes_o)
for node in nodes_ids:
    x, y = G.nodes[node]["pos"]
    node_x.append(x)
    node_y.append(y)

node_trace = go.Scatter(x=node_x, y=node_y, mode="markers", hoverinfo="text",
                        marker=dict(color=[], size=50, line_width=10))
node_trace.text = [f"TEXT{idx}" for idx, _ in G.adjacency()]

# Create Network Graph
fig = go.Figure(
    data=[edge_trace, node_trace],
    layout=go.Layout(),
)
fig.show()

```

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [November 30, 2022, 1:11pm UTC](https://community.plotly.com/t/python-networkx-plotly-how-to-display-edges-mouse-over-text/70350/2 "2022-11-30T13:11:33Z")

</div>

@Jedi  
I explained in this thread [https://community.plotly.com/t/displaying-edge-labels-of-networkx-graph-in-plotly/39113](https://community.plotly.com/t/displaying-edge-labels-of-networkx-graph-in-plotly/39113) how to display some information associated to edges.

---

<div class="post-metadata">

**Author:** ![Jedi](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@Jedi](https://community.plotly.com/u/Jedi)\
**Post date:** [November 30, 2022, 8:44pm UTC](https://community.plotly.com/t/python-networkx-plotly-how-to-display-edges-mouse-over-text/70350/3 "2022-11-30T20:44:38Z")

</div>

[empet](https://community.plotly.com/u/empet)  
Many thanks for your answer!  
The solution to the same question can be found in [stackoverflow](https://stackoverflow.com/questions/74607000/python-networkx-plotly-how-to-display-edges-mouse-over-text/74633879#74633879)
