Introduction to Data Visualization with Plotly in Python
Alex Scriven
Data Scientist
Allows the user to select from a set of options
Updates data or layout elements
$$
fig = go.Figure()
for suburb in ['Ashfield', 'Lidcombe', 'Bondi Junction']: df = syd_houses[syd_houses.Suburb == suburb]
fig.add_trace( px.bar(df, x='Year', y='Median House Price').data[0])
$$
visible
argument determines whether traces are visible (True
) or not (False
)args
to update the visible
argument of different tracesargs:[{'visible': [True, False, False]}]
# Create the dropdown dropdown_buttons = [ {'label': 'Ashfield', 'method': 'update',
'args': [{'visible': [True, False, False]}, {'title': 'Ashfield'}]},
{'label': 'Lidcombe', 'method': 'update',
'args': [{'visible': [False, True, False]}, {'title': 'Lidcombe'}]},
{'label': 'Bondi Junction', 'method': 'update',
'args': [{'visible': [False, False, True]}, {'title': 'Bondi Junction'}]}
]
$$
fig.update_layout({
'updatemenus':[{
'type': "dropdown",
'x': 1.3,
'y': 0.5,
'showactive': True,
'active': 0,
'buttons': dropdown_buttons}]
})
fig.show()
$$
Introduction to Data Visualization with Plotly in Python