I'm new to plotly with Python and I have a question. I can't find the solution somewhere else. I want to make buttons to toggle traces on and off in the graph so you can look to traces individually or compare two traces. Here is my code now! Can someone explain to me how this works.
trace =[go.Scatter(x=df["Topic", "Regions", "Periods"], y=df["Price index purchase prices|Price index of existing own homes","Amsterdam", "2010 = 100"],
mode='lines+markers',
name='Amsterdam',visible=True),
go.Scatter(x=df["Topic", "Regions", "Periods"], y=df["Price index purchase prices|Price index of existing own homes","Rotterdam", "2010 = 100"],
mode='lines+markers',
name='Rotterdam',visible=True),
go.Scatter(x=df["Topic", "Regions", "Periods"], y=df["Price index purchase prices|Price index of existing own homes","Zuid-Holland (PV)", "2010 = 100"],
mode='lines+markers',
name='Zuid-Holland',visible=True),
go.Scatter(x=df["Topic", "Regions", "Periods"], y=df["Price index purchase prices|Price index of existing own homes","Noord-Brabant (PV)", "2010 = 100"],
mode='lines+markers',
name='Noord-Brabant',visible=True),
go.Scatter(x=df["Topic", "Regions", "Periods"], y=df["Price index purchase prices|Price index of existing own homes","Groningen (PV)", "2010 = 100"],
mode='lines+markers',
name='Groningen',visible=True),
go.Scatter(x=df["Topic", "Regions", "Periods"], y=df["Price index purchase prices|Price index of existing own homes","Nederland", "2010 = 100"],
mode='lines+markers',
name='Nederland', visible=True)]
layout = go.Layout(
xaxis=go.layout.XAxis(
type='category',
title='Periode'
),
yaxis=go.layout.YAxis(
title='Prijsindex, 2010 = 100'
),
title="Prijsindex van de huisprijzen in de Randstad"
)
fig = go.Figure(data=trace, layout=layout)
fig.update_layout(
updatemenus=[
dict(
type = "buttons",
direction = "left",
buttons=list([
dict(
args=["visible", "False"],
label="Amsterdam",
method="restyle"
)
]),
pad={"r": 10, "t": 10},
showactive=True,
x=0.0,
xanchor="left",
y=1.15,
yanchor="top"
),
]
)
fig.show()
Thanks!