Skip to content Skip to sidebar Skip to footer

Plotly: How To Update One Specific Trace Using Updatemenus?

This is a follow-up question to Plotly: Plotly: How do the buttons for the update menus really work? Consider the following plotly figure produced by the code snippet below: Plot:

Solution 1:

In the list you are passing to args for each button, you can add an integer after the dict to indicate which trace you want to update. For example the following will update the first trace only (i.e. the one at index=0)

buttons=list([dict(args=[{'y':[df1['A'],df1['B']]}, [0]], # note the `, [0]` here!

                   label="df1",
                   method="restyle"
                ),
                dict(args=[{'y':[df2['A'], df2['B']]}, [0], # note the `, [0]` here!

                    label="df2",
                    method="restyle"
                )
            ])

Post a Comment for "Plotly: How To Update One Specific Trace Using Updatemenus?"