How to highlight traces based on legend hover events?

Hi guys,

I want to create a plotly fig that highlight on the hover event an item on the legend.

Is the same animation from this D3js’ example: https://www.d3-graph-gallery.com/bubble.html

My plotly’s code is something like that:

import plotly.graph_objects as go
import plotly.io as pio

fig = go.Figure()

for intent in intents:
    temp = self.data[self.data["intent"] == intent].copy()

    fig.add_trace(go.Scatter(
        x=temp["x"], y=temp["y"],
        mode="markers",
        text=temp["example"],
        opacity=0.6,
        name=intent,
        hovertext=temp["hovertext"],
        hoverinfo="text"
    ))

fig.update_layout(
    title_text="Example Analysis",
)

Someone can help me?

Hey guys,

I was thinking about this feature (highliting trace based on legend hover) and it is really nicely shown in the link attached in this original post so I decided to bump it. Before diving deep some hacky paths, does someone managed to implement this? I believe that there is no way to catch legend hover so the only way would be to implement legend as some another type of component. Another idea is to hack default legend click events so i.e. on double click all other traces do not diappear but get dimmed.

(now I noticed that this is Plotly post, maybe it would be more suitable for Dash)

Hey @martin2097.

I answered a similar question a while ago, instead of hovering the OP wanted to use the click Event. Maybe this helps:

1 Like

Hi guys,
I run into the same request: hovering over the legend entry and highlight the corresponding trace.
Did someone find a working solution?