Black Lives Matter. Please consider donating to Black Girls Code today.

Set traces to be toggled off by default

I’m creating a visualization that has 6 different histograms overlaid. By default, I would like only the first two to be visible. Then if the user chooses, they can click the traces in the legend to toggle the other 4 to be visible.

Is that possible?

Hi @jmillz, this is possible : graph_objects traces have a visible attribute which can be set to legendonly, and then you can click on the trace name in the legend if you want them to become visible. For example

import plotly.graph_objects as go
fig = go.Figure(go.Scatter(y=[1, 2, 3]))
fig.add_trace(go.Scatter(y=[3, 4, 5], visible='legendonly'))

In fact we should add an example using legendonly to (unless you want to contribute it yourself of course!).