✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Buttons for switchable [on\off] traces


I’m making figures using python 3.5, and having trouble with buttons.
In this case I am making a histogram with barmode = ‘overlay’, with multiple traces.

I want to be able to switch each trace on or off using buttons.

Following the examples on the tutorial page, I was able to use the following format:

updatemenus = list([
buttons =list([
label = ‘Age’,
method = ‘update’,
args = [{‘visible’ : [True,False,False]}]),
label = ‘Copper’,
method = ‘update’,
args = [{‘visible’ : [False,True,False]}]),
label = ‘Gold’,
method = ‘update’,
args = [{‘visible’ : [False,False,True]}]),
label = ‘All’,
method = ‘update’,
args = [{‘visible’ : [True,True,True]}])

This toggles visibility for the traces, but there are many more traces I want to plot, and this gets impractical. I would like to be able to have a single button for each trace, so that each could be toggled between “visible/hidden”, rather than have to make a custom button with boolean [True, False, True,…] for each possible permutation.

Is this possible?

Thanks for your help.

(Edit: To be clear, I want to be able to display a custom selection from a larger group of traces by toggling them on or off with a button. If I use the method above, I have to create a button for each possible combination of on\off states, which is impractical.)

Have you noticed that you can click the legend to toggle traces? If you double click an item in the legend, it will hide all traces except for the one you double clicked. Using the legend might be easier than buttons for your use case.

Wow. I had no idea that was even a built-in feature. Thanks!

One problem I am finding with this feature of the legend is that when the legend items are part of a tracegroup (which I use for legend separation between subplots) then the entire group is toggled on/off. Have tried setting itemclick and itemdoubleclick properties of the legend but cannot undo this behaviour.

Anyone been able to keep individual legend entry toggling while grouping traces?