Hi @bgivens33,
I think you will actually have to change the figure.
Without looping it’ll get difficult, but at least you don’t need to loop “manually” as you can use for_each_trace()
An example:
- create 100 traces
- assign random name out of 10 names
import plotly.graph_objects as go
import random
fig = go.Figure()
for _ in range(100):
fig.add_scatter(
x=np.arange(10),
y=np.random.randint(0,10,10),
name=random.choice([f'Trace{i}' for i in range(10)]),
visible=True
)
fig.update_layout(height=600, width=600)
Pretty crowded, right? Define your HideOut
myHideout = ["Trace1","Trace2","Trace3"]
fig.for_each_trace(lambda x: x.update({'visible': ['legendonly', True][x.name in myHideout]}))
If you want to hide the trace completely (including legend):
fig.for_each_trace(lambda x: x.update({'visible': x.name in myHideout}))
You could also use the Patch()
in a similar way, this time you will have to loop “manually” thru all traces: