How to display different df in plotly with an menue

32 Views Asked by At

I'd like to display an plotly plot with the ability to change / filter the df with an dropdownmenue.

TimeStamp L001_1 L001_2 L001_3 L002_1 L002_2 L003_1 L003_2
1.1.2023 1 2 2 3 4 4 2
2.1.2023 2 4 5 4 6 4 3


df_L001 = df.filter(regex='L001|TimeStamp')
df_L001 = df_L001.set_index('TimeStamp')

df_L002 = df.filter(regex='L002|TimeStamp')
df_L002 = df_L002.set_index('TimeStamp')

df_L003 = df.filter(regex='L003|TimeStamp')
df_L003 = df_L003.set_index('TimeStamp')


x = df['TimeStamp'].unique()



fig = go.Figure()




for col in df_L001.columns[1:]:
    fig.add_trace(go.Scatter(y=df_L001[col], x=df_L001.index, name=col))
for col in df_L002.columns[1:]:
    fig.add_trace(go.Scatter(y=df_L002[col], x=df_L002.index, name=col))
for col in df_L003.columns[1:]:
    fig.add_trace(go.Scatter(y=df_L003[col], x=df_L003.index, name=col))


fig.update_layout(title_text='Load',
                 xaxis_title='Date', yaxis_title='Load')


fig.update_layout(
    updatemenus=[
        dict(active=0,
            buttons=list([
            dict(label="None",
                 method="update",
                 args=[{"visible":[True,True,True]},
                       {"title":"ALL"}]),
            dict(label="L001",
                 method="update",
                 args=[{"visible":[True, False, False]},
                       {"title":"L001"}]),
            dict(label="L002",
                 method="update",
                 args=[{"visible":[False,True,False]},
                       {"title":"L002"}]),
            dict(label="L003",
                 method="update",
                 args=[{"visible":[False,False,True]},
                       {"title":"L003"}]),
        ]),
        )
    ]
)

fig.show()

I get it, that the "visible":[False,False,True] is wrong, but I don't find a solution.

Thanks

0

There are 0 best solutions below