The animate
and animation_options
parameters in Dash’s Graph component control how your visualizations transition between updates. These parameters are essential for creating smooth, interactive data visualizations that respond to user input or real-time data updates.
How do animations work?
When enabled, animations create smooth transitions between graph updates instead of abrupt changes. This includes transitions for data points, axes ranges, and other visual elements. The animations can be customized using animation_options
to control timing, easing, and transition modes.
Official Documentation
From the documentation:
animate
(boolean; defaultFalse
): Beta: If True, animate between updates using plotly.js’sanimate
function.
animation_options
(dict; default{ frame: { redraw: False, }, transition: { duration: 750, ease: 'cubic-in-out', },}
): Beta: Object containing animation settings. Only applies ifanimate
isTrue
.
Parameter Values:
animate
True
: Enables automatic animations for all updatesFalse
(default): Disables animations
animate_options
The animate_options
dictionary can include:
{
'frame': {
'redraw': True # Whether to redraw the entire graph
},
'transition': {
'duration': 500, # Duration of transition between frames
'easing': 'cubic-in-out' # Easing function to use
},
'mode': 'immediate' # Animation mode
}
The documentation do not say exactly what redraw
does. As its impact is unclear, we recommend keeping it to True
.
Defining
redraw
: Settingredraw: false
is an optimization for scatter plots so that animate just makes changes without redrawing the whole plot. For other plot types, such as contour plots, every frame must be a total plot redraw, i.e.redraw: true
.
Good to know: under the hood, the plotly charting library is handling animations. You will therefore find more information on this page: https://plotly.com/python/animations/.
Code Examples and Use Cases
1. Basic Animation (animate=True)
Use this for simple animations with default settings:
html.Div([
dcc.Graph(
animate=True,
figure=base_figure,
style={'height': '100%'}
)
], style={
'width': '100%',
'height': '400px',
'border': '1px solid #ddd',
'padding': '10px'
})
2. Customized Animation with Options
Use this when you need precise control over animation timing and behavior:
# Example of linear, 2s animation
html.Div([
dcc.Graph(
figure=fig
animate=True,
animation_options={
'transition': {
'duration': 500,
'easing': 'linear'
}
},
)
])
The easing parameter will accept all following values (source):
"linear"
| "quad"
| "cubic"
| "sin"
| "exp"
| "circle"
| "elastic"
| "back"
| "bounce"
| "linear-in"
| "quad-in"
| "cubic-in"
| "sin-in"
| "exp-in"
| "circle-in"
| "elastic-in"
| "back-in"
| "bounce-in"
| "linear-out"
| "quad-out"
| "cubic-out"
| "sin-out"
| "exp-out"
| "circle-out"
| "elastic-out"
| "back-out"
| "bounce-out"
| "linear-in-out"
| "quad-in-out"
| "cubic-in-out"
| "sin-in-out"
| "exp-in-out"
| "circle-in-out"
| "elastic-in-out"
| "back-in-out"
| "bounce-in-out"
Best Practices & Tips
- Keep transitions under 1000ms for optimal user experience (150-300ms are good!).
- Remember to update the figure layout (x_min, x_max, …) if you add new points or modify data, otherwise it might not become visible.