Introduction to Data Visualization with Plotly in Python
Alex Scriven
Data Scientist
Custom buttons can:
Update the data or layout elements of a plot
update_layout() customizations could be in a button!Assist with animations (beyond the scope of this course)
Added via an updatemenus argument with arguments:
type: buttons or dropdowndirection: Button orientationleft) or on top of (down) each otherx/y: Floats to set the button positionsshowactive: True/False to show the active (index of button) as pressed or not.buttons: A list of button objects$$
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'}]}]
One of the most confusing parts of Plotly!
[{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()
$$

Introduction to Data Visualization with Plotly in Python