Hi,
I am trying to make a single chart containing one or two lines with the use of dropdown boxes. Currently I have two dropdown boxes with each the same lines from the dataset. If I click on a line from either of the dropdown boxes it now only plots one of the lines and removes the other. But I want the option to only display one line from the first dropdown box and a none option from the second. And I want to be able to select a second line from the second dropdown box and have it be plotted along with the line from the first box.
This is my code currently:
def multi_plot(df, addAll=True):
fig = go.Figure()
for column in df.columns.to_list():
fig.add_trace(
go.Scatter(
x = df.index,
y = df[column],
name = column
)
)
button_all = dict(label = 'All',
method = 'update',
args = [{'visible': df.columns.isin(df.columns),
'title': 'All',
'showlegend':True}])
def create_layout_button(column):
return dict(label = column,
method = 'update',
args = [{'visible': df.columns.isin([column]),
'title': column,
'showlegend': True}])
fig.update_layout(
updatemenus=[
dict(
y = 1,
buttons=([button_all] * addAll) + list(df.columns.map(lambda column: create_layout_button(column)))
),
dict(
y = 0.9,
buttons=([button_all] * addAll) + list(df.columns.map(lambda column: create_layout_button(column)))
)
]
)
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label="1m",
step="month",
stepmode="backward"),
dict(count=6,
label="6m",
step="month",
stepmode="backward"),
dict(count=1,
label="YTD",
step="year",
stepmode="todate"),
dict(count=1,
label="1y",
step="year",
stepmode="backward"),
dict(step="all")
])
),
rangeslider=dict(
visible=True
),
type='date'
)
)
fig.show()