Skip to content

Animations in Plotly

Why animations

Animations are useful when you want to show change over time as motion, not just as a static trend line:

  • GDP vs life expectancy by year
  • Covid cases by month

Under the hood, Plotly builds one frame per value of your animation column, then adds Play/Pause controls and a slider that swap between frames. It’s not “real” motion — it’s the same trick as a flipbook, just automated.

Animated scatter (classic example)

Animated scatter
import plotly.express as px
 
df = px.data.gapminder()
 
fig = px.scatter(
    df,
    x="gdpPercap",
    y="lifeExp",
    size="pop",
    color="continent",
    hover_name="country",
    log_x=True,
    size_max=60,
    animation_frame="year",
    animation_group="country",
    title="Gapminder: GDP vs Life Expectancy (animated)",
)
 
fig.show()
Animated scatter
import plotly.express as px
 
df = px.data.gapminder()
 
fig = px.scatter(
    df,
    x="gdpPercap",
    y="lifeExp",
    size="pop",
    color="continent",
    hover_name="country",
    log_x=True,
    size_max=60,
    animation_frame="year",
    animation_group="country",
    title="Gapminder: GDP vs Life Expectancy (animated)",
)
 
fig.show()

animation_frame="year"animation_frame="year" tells Plotly to build one frame per year; animation_group="country"animation_group="country" tells it which points in different frames are “the same point” so a bubble smoothly moves/resizes instead of popping to a new spot each frame.

sketch Animation = swapping between precomputed frames p5.js
Each 'year' is a frame; points move smoothly between their positions in consecutive frames, like a flipbook.

Tips

  • Animations work best with fewer points (or aggregation) — dozens of moving bubbles read clearly, thousands become a blur.
  • Add animation_groupanimation_group so Plotly tracks each entity across frames instead of treating every frame as unrelated data.
  • Consider facets if animation is too visually busy — sometimes seeing all years at once, side by side, communicates the trend faster than watching it play out.
diagram How Plotly animation frames work mermaid
One data slice per animation value becomes one frame; animation_group links the same entity across frames.

Next

This wraps the interactive visualization phase — continue to Phase 8: Statistics for Data Analytics to build the analytical foundations behind these charts.

🧪 Try It Yourself

Exercise 1 – Animate Over a Column

Exercise 2 – Track Entities Across Frames

Exercise 3 – Use a Log Axis for Skewed Data

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did