Buttons for switchable [on\off] traces


#1

Hello,

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([
dict(type=“buttons”,
buttons =list([
dict(
label = ‘Age’,
method = ‘update’,
args = [{‘visible’ : [True,False,False]}]),
dict(
label = ‘Copper’,
method = ‘update’,
args = [{‘visible’ : [False,True,False]}]),
dict(
label = ‘Gold’,
method = ‘update’,
args = [{‘visible’ : [False,False,True]}]),
dict(
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.)


#2

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.


#3

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