I was learning plotly dropdown menu and stumbled on a label problem.
Question
- How to show labels
sin and sin-1when selected Sine. And show labelstan and tan-1when selected Tan?
MWE
# imports
import plotly.graph_objects as go
import numpy as np
# data
x = np.linspace(-np.pi, np.pi, 100)
y1 = np.sin(x)
y1b = y1-1
y2 = np.tan(x)
y2b = y2-1
# plotly setup
fig = go.Figure()
# Add one ore more traces
fig.add_traces(go.Scatter(x=x, y=y1,name='sin'))
fig.add_traces(go.Scatter(x=x, y=y1b,name='sin - 1'))
fig.add_traces(go.Scatter(x=x, y=y2,name='tan'))
fig.add_traces(go.Scatter(x=x, y=y2b,name='tan - 1'))
# construct menus
updatemenus = [{'buttons': [{'method': 'update',
'label': 'Sine',
'args': [{'y': [y1, y1b]},]
},
{'method': 'update',
'label': 'Tan',
'args': [
{'y': [y2, y2b],'label':['a','b']},
]}
],
'direction': 'down',
'showactive': True,}]
# update layout with buttons, and show the figure
fig.update_layout(updatemenus=updatemenus)
fig.show()




