Introduction to Data Visualization with Plotly in Python
Alex Scriven
Data Scientist
An interactive element to toggle between values and update a plot
Used for viewing data over time
Can be used for any group
$$
$$
$$
A year slider:

A penguin island slider:

animation_frame What will be on the slider (Year or Island on the previous slide)$$
animation_group: Identifies which samples stay consistent across framesfig = px.scatter( data_frame=revenues, y='Revenue', x='Employees', color='Industry',animation_frame='Year', animation_group='Company')fig.update_layout({ 'yaxis': {'range': [0, 500000]}, 'xaxis': {'range': [-100000, 2500000]} })fig['layout'].pop('updatemenus') fig.show()

plotly.express implements sliders using animate method
$$
fig['layout']['sliders'][0].steps[0]['method']
animate
$$
fig = go.Figure()for island in ['Torgersen', 'Biscoe', 'Dream']: df = penguins[penguins.Island == island]temp_trace = px.scatter(df, x="Culmen Length (mm)", y="Culmen Depth (mm)") fig.add_trace(temp_trace.data[0])
sliders = [ {'steps':[{'method': 'update', 'label': 'Torgersen','args': [{'visible': [True, False, False]}]},{'method': 'update', 'label': 'Bisco','args': [{'visible': [False, True, False]}]},{'method': 'update', 'label': 'Dream','args': [{'visible': [False, False, True]}]}]} ]
$$
More formatting options available in the documentation
$$
fig.update_layout({'sliders': sliders})
fig.show()
  
Introduction to Data Visualization with Plotly in Python