Pythonで学ぶPlotlyによるデータ可視化入門
Alex Scriven
Data Scientist
カスタムボタンでできること:
プロットのデータやレイアウト要素を更新
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で最も混乱しやすい部分の1つ!
[{dictionary to send to data}, {dictionary to send to layout}]

dir(fig.layout)

'args'で任意の引数を更新可能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によるデータ可視化入門