Reputation: 1858
I have the following figure definition:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1,2,3], y=[1,2,3], name="A"))
fig.add_trace(go.Scatter(x=[1,2,3], y=[1,3,5], name="B"))
fig.show()
I would like to highlight a trace upon hover, which would reduce the opacity of all other traces and make the selected one bold preferably.
Is there a way to achieve this?
Upvotes: 2
Views: 3643
Reputation: 1858
Thanks to vestland, I think I managed to get it working by following this link. I had to change go.Figure
to go.FigureWidget
and I also had to add a update_trace
method that appears in the provided link. Then I changed on_click
callback to on_hover
and it worked. The solution isn't ideal, I don't really like the fact that we need to loop over each data point and I don't like that the update_trace
function relies on go.FigureWidget
object from outer scope, so if anyone has a cleaner way to solve this, please let us know.
Upvotes: 2