Plot legends but initially be off!

Hi there

We know that legends on Plotly can be turn off or on. When we plot, we can turn off data using legends and turn them on again.

I need that initially when the plot becomes appear, the legends be off and user if want to see them turn them on. How can I do it?


you mean like this?

import plotly.graph_objs as go

fig.add_scatter(y=[1, 1, 1],  line={'color': 'red'},name='Firsttrace')
fig.add_scatter(y=[2, 2, 2],  line={'color': 'blue'},name='Secondttrace')
fig.add_scatter(y=[3, 3, 3],  line={'color': 'black'},name='Thirdtrace')
fig.add_scatter(y=[4, 4, 4],  line={'color': 'gold'},name='Forthtrace', visible='legendonly');

The last trace is not shown in the chart but is shown in the legend.



That was exactly what I needed. Thanks :+1: :ok_hand:

1 Like

Is there a plotly express equivalent? or we should use this underlying api for this effect?