Skip to content

Animations in Plotly

Why animations

Animations are useful when you want to show change over time:

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

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()

Tips

  • Animations work best with fewer points (or aggregation).
  • Add animation_groupanimation_group so Plotly tracks each entity across frames.
  • Consider facets if animation is too visually busy.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did