Python 中的 Plotly 数据可视化入门
Alex Scriven
Data Scientist
自定义按钮可以:
更新图的 data 或 layout 元素
update_layout() 自定义都可放进按钮!辅助动画(超出本课范围)
通过 updatemenus 参数添加,常用参数:
type:buttons 或 dropdowndirection:按钮方向left)或上下(down)排列x/y:浮点数,设置按钮位置showactive:True/False,是否显示被按下的 active(按钮索引)buttons:button 对象列表$$
fig = px.bar(
data_frame=revenues,
x='Industry', y='Revenue',
color='Industry')
fig.show()

my_buttons = [{'label': "Bar plot",'method': "update",'args': [{"type": "bar"}]},{'label': "scatterplot",'method': "update",'args': [{"type": "scatter", 'mode': 'markers'}]}]
Plotly 最让人困惑的部分之一!
[{dictionary to send to data}, {dictionary to send to layout}]

dir(fig.layout)

dir(fig.data[0])

$$
fig.update_layout({ 'updatemenus': [{'type': "buttons",'direction': 'down', 'x': 1.3, 'y': 0.5,'showactive': True, 'active': 0,'buttons': my_buttons}] }) fig.show()
$$

Python 中的 Plotly 数据可视化入门