Skip to content

Instantly share code, notes, and snippets.

@avapolzin
avapolzin / gist:f4824060d4c579f37619cfd4d3f98229
Last active August 16, 2026 02:08
Using dropdowns to toggle which traces are shown with Plotly
"""
I'm sure others have figured this out, too, but on a search I found no answers on any fora that actually addressed how to use
Plotly's built-in features to show individual traces without impacting the visibility of the others. The example is taken directly
from an interactive I made (you can see the example here: https://questdwarfs.github.io/assets/html/quest_compare_spectra.html), so
some of what is here will be extraneous for the one point (and I'm sure there are inefficiencies here as I only ever use Plotly
occasionally). The steps are roughly:
1) generate your traces with visibility toggled off (this is also part of the Plotly tutorial)
2) instead of using *update* in your dropdown, you'll use *relayout*, which will let you specify which tracers are impacted
when you change visible to True for the trace of interest