Python 中的 Plotly 数据可视化入门
Alex Scriven
Data Scientist
允许用户从一组选项中选择
可更新数据或布局元素

$$
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 参数决定 trace 是否可见(True)或不可见(False)args 更新不同 trace 的 visible 参数args:[{'visible': [True, False, False]}]

# 创建下拉菜单 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()
$$

Python 中的 Plotly 数据可视化入门