As the title implies, is there a way to make an annotation dissapear/appear by clicking on the corresponding trace in the legend of a plotly chart?
Suppose I have a scatterplot with a nonlinear trendline I added with add_trace. The trendline has an entry in the legend box and I want to display/hide the equation for the trendline when I toggle the trace on/off in the legend box.
The annotations have a visible property that can be accessed, and I read about the layout.legend.itemclick but it only covers the events of the affected trace, no option to include an object like an annotation.
Hi @PL_PUAR welcome to the forum! The easiest thing to do would be to make the equation part of the trace by using the text argument of a go.Scatter trace (you can add it to the first or the middle data point and the other items can just be empty strings).
Would you be able to provide an example of what the solution would look like? I’m trying to graph two separate things in a scatterplot now and, while clicking on the legend will toggle the markers on and off properly, it doesn’t toggle the associated annotations off and on.