🚀 Jumpstart 2027: Custom, Secure AI Workflows to Adopt Now. Reserve your spot →

Chris Parmer

Chris Parmer

October 27, 2026

Bar Chart Races - A Complete Guide (with 12 Examples)

TL;DR

  • A bar chart race is an animated horizontal bar chart: each frame shows one period's top items, sorted largest first, and the bars slide past each other as the ranking changes.
  • Bar chart races are also known as racing bar charts and racing charts, and are similar to bump charts and slope charts.
  • Use one to show how a ranking changed over many periods, when the motion is the story and readers can watch it (a video, a social post, a talk). For careful comparison, a line chart or a bump chart is better.
  • You can make a bar chart race with Plotly from a go.Bar trace and animation frames, and the short make_bar_race helper below does it in one call.
  • Sort the bars in every frame, add in-between frames so bars slide instead of jumping, keep one color per item for the whole race, and put a large period label on the chart.

What is a bar chart race?

Bar chart races look like this:

Animated bar chart race of the 10 largest oil producers each year from 1965 to 2024. The United States leads at the start, the USSR takes over in 1975, Saudi Arabia leads from 1992, and the US has been first every year since 2017, with 9,977 TWh in 2024, 1.6 times Russia

Data: Energy Institute Statistical Review of World Energy, via Our World in Data.

How do you read a bar chart race? In the example above, notice these things:

  • Each frame is one year, shown in large gray digits at the bottom right, and each bar is one country's oil production that year. The 10 largest producers are sorted from the top, with the value printed at the end of each bar.
  • Between years the bars slide to their new places, so an overtake shows up as one bar moving past another. Watch the green Saudi Arabia bar climb from the middle of the list to first place in 1992.
  • The countries that lead the story keep their own color in every frame, such as the blue United States, the red Russia / USSR bar and green Saudi Arabia, and the rest are gray. That makes it easy to follow one country while the others shuffle around it.
  • Countries enter and leave at the bottom as they move in and out of the top 10, which is how Brazil and the United Arab Emirates, missing from the first frame, are in the last one.
  • The x axis rescales as production grows, so a bar of the same length in two frames is not the same amount. The US bar fills the width in both the first and last frames, although it produced about twice as much in 2024.

It's often used for charts like these:

Bar chart race of the 10 largest economies by GDP from 1960 to 2024, colored by World Bank region, shown at 2024: the US at $29,298B, China at $18,730B and Japan at $4,190B

Countries over decades. China went from the 12th largest economy in 1980 to 2nd every year since 2010, and its 2024 GDP was 4.5 times Japan's. Data: World Bank, World Development Indicators.

Bar chart race of the 10 brand-name drugs with the highest Medicare Part D spending, 2020-2024, with GLP-1 drugs in blue, shown at 2024: Eliquis $20.8B, Ozempic $13.0B, Jardiance $11.4B and Mounjaro $6.3B

Products climbing a market. Ozempic rose from the 27th costliest drug in Medicare Part D in 2020 ($1.5B) to 2nd in 2024 ($13.0B). Data: CMS Medicare Part D Spending by Drug.

Animated bar chart race of Formula 1 career wins after each of 1,149 races from 1950 to 2025. Fangio, Clark, Stewart, Prost and Schumacher take turns at the top, and Lewis Hamilton passes Schumacher's 91 wins in 2020 and finishes on 105

Running totals in sport. Lewis Hamilton passed Michael Schumacher's record of 91 Formula 1 wins at the 2020 Portuguese Grand Prix and has 105. Data: Jolpica F1 API.

A short history

Flourish's team says it made a race of sorts for the British Council around six years earlier, but the name and the craze date from March 2019. Flourish traces the trend to a February 2019 tweet by Matt Navarra and to John Burn-Murdoch of the Financial Times, who on 18 March 2019 posted a race of the world's 10 biggest cities since 1500 and published his code. Flourish added a no-code template three days later. Here is his chart redrawn with Plotly on the data his notebook used, which draws on the historical urban populations of Reba, Reitsma and Seto (2016):

Bar chart race of the world's largest cities from 1500 to 2018, redrawn with Plotly from the data behind John Burn-Murdoch's 2019 chart and shown at 1900, when London (6.48 million), New York (4.24 million) and Paris (3.33 million) led

Alternatives to a bar chart race

Here's the same oil production data drawn four other ways. Some are better for the question, some worse, some just different:

The world's largest oil producers drawn four ways: small multiples of the top 5 in 1965, 1985, 2005 and 2024; a line chart of production since 1965; a bump chart of ranks; and a slope chart of 1965 vs 2024
  • Line chart (better for analysis). Every year is visible at once, so readers can compare any two points without waiting for the animation. It gets crowded past about eight lines.
  • Bump chart (better when the order is the question). Plots the rank itself, so every swap is a crossing line; it hides the size of the gaps. See our bump chart guide.
  • Small multiples (works too, for a few key years). A static row of bar charts for chosen years works in print and in reports, where an animation can't play.
  • Slope chart (different). Compares two dates and skips everything in between. See our slope chart guide.

A bar chart race wins when you have one shot at attention, such as a social post, a talk or the top of a page, and the order changes many times. Readers remember the motion but can't easily go back to a moment, which is why the slider matters.

How to make a bar chart race

With AI

ChatGPT, Claude Code, GitHub Copilot, Cursor and other AI tools are excellent at writing Plotly code. Name Plotly in the prompt, say what one frame should show, and list the checks you want:

Make a plotly bar chart race from production.csv (columns: year, country, twh).
- One horizontal go.Bar trace animated with frames; the top 10 countries in each frame,
largest at the top (bar position = rank, y axis range [10.5, 0.5], hidden).
- 4 in-between frames per year: interpolate both the values and the ranks linearly.
- One fixed color per country for the whole race; gray for countries I don't name.
- Country names left of the bars, values at the bar ends ("9,977 TWh"), the year in large
gray text in the lower right.
- A Play button and a slider with one step per year; frame duration 60 ms, redraw True.
- A title that states the main takeaway.
- Print the top 3 for the first and last year so I can check them.
- Save it as race.html.

With Plotly Studio

Plotly Studio is a product for creating data visualizations and Dash apps and for analyzing data with AI, available as a desktop app or embedded in Dash apps. Ask for a bar chart race the same way:

Show a bar chart race of the top 10 countries by oil production each year, sorted largest first, with smooth transitions between years, a play button and a year slider, and a dropdown to switch to gas production.

Make a bar chart race in Python or JavaScript

This is the code AI tools write under the hood. Plotly Express animates a bar chart with one argument, which is enough for a draft. The bars keep one order for the whole animation and jump between frames, though:

import plotly.express as px
df = px.data.gapminder()
top = df[df["pop"] >= df.groupby("year")["pop"].transform(lambda s: s.nlargest(10).min())]
fig = px.bar(top, x="pop", y="country", color="country", orientation="h",
animation_frame="year", range_x=[0, 1.4e9])
fig.update_yaxes(categoryorder="total ascending")
fig.show()

For a real race, this helper sorts every frame, adds in-between frames and keeps colors fixed. Every example in this guide builds on it:

import pandas as pd
import plotly.graph_objects as go
def make_bar_race(df, time, entity, value, top_n=10, steps=4, colors=None):
"""A bar chart race: sorted bars per frame, in-between frames, one color per entity."""
wide = df.pivot_table(index=time, columns=entity, values=value).sort_index().fillna(0)
ranks = wide.rank(axis=1, ascending=False, method="first")
palette = ["#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4", "#008300", "#6250d6", "#e34948"]
colors = colors or {e: palette[i % 8] for i, e in enumerate(wide.max().sort_values(ascending=False).index)}
frames = []
for i in range(len(wide) * steps - steps + 1):
a, f = divmod(i, steps)
b = min(a + 1, len(wide) - 1)
v = wide.iloc[a] * (1 - f / steps) + wide.iloc[b] * f / steps # values slide between periods
r = ranks.iloc[a] * (1 - f / steps) + ranks.iloc[b] * f / steps # and so do the bar positions
keep = r.sort_values().index[:top_n + 1]
frames.append(go.Frame(name=str(i), data=[go.Bar(
x=v[keep], y=r[keep], orientation="h", text=list(keep), textposition="outside",
marker_color=[colors.get(e, "#c3c2bc") for e in keep])],
layout=dict(title=f"{wide.index[a]}", xaxis_range=[0, v.max() * 1.25])))
fig = go.Figure(data=frames[-1].data, layout=frames[-1].layout, frames=frames)
fig.update_yaxes(range=[top_n + 0.5, 0.5], visible=False) # rank 1 at the top
play = dict(frame=dict(duration=60, redraw=True), transition=dict(duration=0), fromcurrent=True)
fig.update_layout(updatemenus=[dict(type="buttons", buttons=[dict(label="Play", method="animate", args=[None, play])])])
return fig
df = pd.read_csv("oil.csv") # columns: year, country, twh
make_bar_race(df, "year", "country", "twh").show()

The examples use a fuller version of the same function that adds names left of the bars, value labels, the large period label and a slider.

In JavaScript, plotly.js takes the frames directly. ids lets a bar keep its identity from one frame to the next, so it slides instead of changing color:

<div id="chart"></div>
<script src="https://cdn.plot.ly/plotly-4.1.1.min.js"></script>
<script>
// Top 5 oil producers (TWh, Energy Institute via Our World in Data)
const years = {
2000: {"Saudi Arabia": 5100, "United States": 4042, "Russia": 3799, "Iran": 2229, "Mexico": 1981},
2010: {"Russia": 5958, "Saudi Arabia": 5388, "United States": 3874, "Iran": 2466, "China": 2361},
2024: {"United States": 9977, "Russia": 6122, "Saudi Arabia": 5933, "Canada": 3372, "Iran": 2727},
};
const colors = {"United States": "#2a78d6", "Russia": "#e34948", "Saudi Arabia": "#1baf7a"};
const frames = Object.entries(years).map(([year, v]) => {
const names = Object.keys(v).sort((a, b) => v[b] - v[a]); // largest on top
return {name: year, layout: {title: {text: year}}, data: [{
type: "bar", orientation: "h", ids: names, // ids let a bar keep its identity between frames
x: names.map(n => v[n]), y: names.map((n, i) => i + 1),
text: names, textposition: "outside",
marker: {color: names.map(n => colors[n] || "#c3c2bc")}}]};
});
Plotly.newPlot("chart", frames[0].data, {
title: {text: "2000"}, xaxis: {range: [0, 12000]}, yaxis: {range: [5.5, 0.5], visible: false},
updatemenus: [{type: "buttons", buttons: [{label: "Play", method: "animate",
args: [null, {frame: {duration: 1000, redraw: true}, transition: {duration: 500}}]}]}],
}).then(() => Plotly.addFrames("chart", frames));
</script>

Share it

Every Plotly chart has a Share chart button (the cloud icon in its toolbar) that uploads it to Plotly Cloud and gives you a link. Only you can see it until you change its visibility.

For a live app, put the chart in a Dash app and publish it with the Plotly Cloud CLI. Coding agents can run these commands for you:

pip install "dash[cloud]"
plotly user login
plotly app publish

If your data has to stay in your own cloud or data center, publish to Dash Enterprise instead.

For a social post, render the frames to images with fig.to_image and join them into an MP4 or GIF with ffmpeg. The GIFs on this page were made that way.

Dos and don'ts

A bar chart race is one sorted bar chart per frame, so most of the work is making each frame readable at a glance. Here is the 2024 frame of the oil race both ways, with the same colors.

Don't keep the bars in a fixed order, squeeze in 15 bars, print raw numbers like 9977.4 or make readers decode a legend:

The 2024 oil production frame with countries in alphabetical order so the US is at the bottom, 15 thin bars, unformatted values such as 9977.4 with the largest cut off, and a legend of 15 countries

Do sort the bars largest first, show the top 10, label names and formatted values on the bars and show the year in large text:

The same frame sorted with the US first at 9,977 TWh, Russia 6,122 TWh and Saudi Arabia 5,933 TWh, ten bars with names on the left and values at the ends, and 2024 in large gray text

Add in-between frames

With one frame per year, bars jump to their new places and readers lose track of who passed whom. Interpolating both the values and the positions makes the bars slide. Here are the positions of two bars as Saudi Arabia passes Russia:

Bar positions of Saudi Arabia and Russia from 1989 to 1994. With one frame per year (dotted) the bars jump between 1st, 2nd and 3rd; with 4 in-between frames per year (solid) they move in steps and cross between 1991 and 1992

Four to six in-between frames per year work for yearly data. Monthly, weekly or per-race data (the Treasury, COVID-19, programming language and F1 races on this page) already moves in small steps and needs none.

Use color for one thing

Here are three options on the GDP race.

One color per item. It works for a handful of items, but over 65 years more than eight countries pass through the top 10, so colors repeat (the US and India here).

The 2024 GDP frame with a different color for each country, where the US and India share blue and Canada and Russia share red

Highlight one story. China is the only color and the other bars are gray.

The 2024 GDP frame with China in red and every other country in gray

By group. Color by region with a legend, so colors never run out and readers can follow a continent.

The 2024 GDP frame colored by World Bank region, with East Asia and Pacific in red, Europe and Central Asia in purple and North America in blue

Whatever you choose, attach colors to the item and never to the rank. A color per rank makes a bar change color when it moves, which is the one thing a race must not do.

Checklist

Do

  • Write a title that states the takeaway, since many readers see only one frame.
  • Sort every frame and show 10 to 12 bars, with one more waiting just below the plot to slide in.
  • Interpolate values and positions for yearly data.
  • Keep each item's color for the whole race, and gray out items that aren't the story.
  • Show the period in large text, and add a slider so readers can stop at a moment.
  • Let the x axis grow with the leader when values grow many times over (the solar race), and fix it when you compare shares (the electricity and programming language races).

Don't

  • Use a legend instead of labels on the bars.
  • Color bars by rank.
  • Run frames faster than about 40 ms, or the labels can't be read.
  • Use a race when readers need exact comparisons; give them a line chart.

Options to customize

These are the options that matter most for building a bar chart race from go.Bar traces and animation frames. The full reference is in the Plotly animations documentation and the bar chart reference.

  1. go.Bar(orientation="h"): horizontal bars, so long names fit on the left.
  2. y = rank (a number): puts each bar at its position; fractional ranks place bars between rows during a swap.
  3. yaxis.range=[N + 0.5, 0.5]: rank 1 at the top, and bar N+1 hidden just below the plot.
  4. go.Frame(name, data, layout): one frame per period or in-between step; layout can change the x range per frame.
  5. ids: matches bars across frames by item, needed when frames use transitions.
  6. marker.color: a list of colors, one per bar, looked up from a fixed item-to-color map.
  7. text, textposition="outside", cliponaxis=False: value labels at the end of each bar.
  8. go.Scatter(mode="text"): names, values or the period label as text that moves with the frame.
  9. layout.updatemenus with method="animate": the Play and Pause buttons.
  10. frame.duration, transition.duration, redraw: speed of the animation; use redraw=True when frames change the axis range.
  11. fromcurrent=True: Play resumes from the current frame instead of the start.
  12. layout.sliders: one step per period, so readers can jump to a year; steps can skip the in-between frames.
  13. xaxis.range in each frame's layout: an axis that grows with the leader; leave it out for a fixed axis.
  14. px.bar(animation_frame=..., animation_group=...): a quick draft without sorting or in-between frames.

More bar chart race examples

Eight more bar chart races built from real public data, each with its source, the technique that makes it work and a prompt to rebuild it.

1. Solar power leaders

Bar chart race of the 10 largest solar power generators from 2005 to 2025, shown at 2025: China 1,175 TWh, the United States 389 TWh, India 196 TWh, Japan 101 TWh and Germany 90 TWh

China has generated the most solar power every year since 2015, and in 2025 it made 1,175 TWh, 3 times the US. The leader in 2005, Japan, made 1.6 TWh, so the x axis has to grow with the race. Data: Ember and Energy Institute via Our World in Data.

Tip: let the x axis rescale every frame (the helper's default), so the early years aren't flat bars at zero.

Get the data from Our World in Data's energy dataset (owid-energy-data.csv, from Ember and the
Energy Institute), solar electricity generation in TWh by country, 2005-2025
(columns: year, country, twh).
Make a plotly bar chart race of the top 10 countries per year with 6 in-between frames per year.
- China, the US, India, Germany and Japan in color, the rest gray.
- The x axis range follows the leader in each frame.
- Title: since when China has led, and China's 2025 output vs the US.

2. Who emitted the most CO2, cumulatively

Bar chart race of cumulative fossil CO2 emissions since 1750 for the top 10 countries, 1850-2024, shown at 2024: the US 435 Gt (23.5% of the world's), China 285 Gt, Russia 123 Gt, Germany 95 Gt and the UK 80 Gt

The UK accounted for 77.8% of all fossil CO2 emitted by 1850. The US passed it in 1911, and by 2024 had emitted 435 billion tonnes, 23.5% of the world's total, with China second at 285. Data: Global Carbon Project via Our World in Data.

Tip: a running total only grows, so the race is about overtakes; two in-between frames per year keep 175 years to a watchable length.

Get the data from Our World in Data's CO2 dataset (owid-co2-data.csv, from the Global Carbon
Project), cumulative CO2 from fossil fuels and industry in million tonnes, countries only,
1850-2024 (columns: year, country, cumulative_co2).
Make a plotly bar chart race of the top 10 in billion tonnes, 2 in-between frames per year,
40 ms per frame, slider steps every 5 years.
- The US, China, the UK, Russia, Germany and India in color.
- Subtitle with the 2024 shares of the world total.

3. US electricity by fuel, month by month

Bar chart race of US electricity generation by fuel over rolling 12 months from December 2003 to June 2026, shown at June 2026: gas 1,821 TWh, nuclear 794, coal 699, wind 483, solar 429 and hydro 255

Gas passed coal as the largest source of US electricity in the 12 months to January 2016, and now makes 40%. Wind passed hydro in 2019 and solar did in January 2024. Data: Ember Monthly Electricity Data (from the US EIA).

Tip: use rolling 12-month totals so seasonal swings don't reorder the bars every month, and fix the x axis so lengths compare across years.

Get the data from Ember's Monthly Electricity Data (monthly_full_release_long_format.csv),
United States, electricity generation by fuel in TWh, 2003-2026
(columns: month, fuel, twh), and compute rolling 12-month sums.
Make a plotly bar chart race with all nine fuels, one frame per month, a fixed x axis.
- Fixed fuel colors: coal #3d3c39, gas #8a8983, nuclear #6250d6, hydro #2a78d6, wind #1baf7a,
solar #eda100, bioenergy #008300.
- Slider steps at each December. Print the first month gas exceeds coal.

4. The largest US banks

Bar chart race of the 10 largest US bank holding companies by assets from 2000 to 2025, shown at 2025, with the four banks that stayed in the top 10 in blue: JPMorgan Chase $3,753B, Bank of America $2,652B, Citigroup $1,836B and Wells Fargo $1,832B

Only 4 of the 10 largest US banks of 2000 were still in the top 10 in 2025. Bank One, FleetBoston, Wachovia, Washington Mutual, National City and SunTrust were bought or failed, and JPMorgan Chase now holds $3.75 trillion. Data: FDIC BankFind Suite (Call Reports).

Tip: color by what happened (survivors blue, banks that disappeared orange) instead of giving each bank its own color.

Get the data from the FDIC BankFind Suite API (financials endpoint, Call Report total assets at
each year end, 2000-2025), summed by top holding company
(columns: year, holding_company, assets_bn).
Make a plotly bar chart race of the top 10 banks, 5 in-between frames per year.
- Blue for banks in the top 10 in both 2000 and 2025, orange for the 2000 top 10 that
left, gray for the rest.
- Values as "$3,753B". Title: how many of the 2000 top 10 are still there.

5. Foreign holders of US Treasuries, every month

Bar chart race of the 10 largest foreign holders of US Treasury securities each month from March 2000 to December 2025, shown at December 2025: Japan $1,186B, the United Kingdom $863B and China $684B

China held more US Treasuries than Japan in at least 117 months between 2008 and 2019 (the file skips the January figures of 2002-2011), and peaked at $1,317B in November 2013. At the end of 2025 Japan held $1,186B, the UK $863B and China $684B. Data: US Treasury, TIC Major Foreign Holders.

Tip: with 300 monthly frames there's no need for in-between frames; put slider steps only at each December so the slider stays readable.

Get the data from the US Treasury's TIC "Major Foreign Holders of Treasury Securities"
historical file (mfhhis01.txt), monthly holdings in US$ billions, 2000-2025
(columns: month, country, holdings_bn).
Make a plotly bar chart race of the top 10, one frame per month, 70 ms per frame.
- Japan, China and the UK in color. Period label like "Dec 2025".
- Print the months in which China ranked first.

6. Confirmed COVID-19 deaths by country

Bar chart race of cumulative confirmed COVID-19 deaths for the top 10 countries, weekly from March 2020 to December 2023, shown at December 2023: the United States 1,164,499, Brazil 702,116, India 533,361 and Russia 401,359

Italy led the count of confirmed COVID-19 deaths in late March 2020, and the US has led since April 12, 2020, reaching 1.16 million by the end of 2023. Confirmed deaths undercount the real toll. Data: WHO COVID-19 dashboard via Our World in Data.

Tip: weekly frames show the first weeks clearly, when the order changed fastest.

Get the data from Our World in Data's COVID-19 dataset (compact.csv, from the WHO dashboard),
total confirmed deaths by country, Sundays from March 2020 to December 2023
(columns: date, country, deaths, per_million).
Make a plotly bar chart race of the top 10, one frame per week, dates shown as "Mar 2020".
- The US, Brazil, India, Italy and Russia in color.
- Note in the subtitle that confirmed deaths undercount the real toll.

Another way to see it: per person, Peru reported 6,587 deaths per million, about twice the US (3,410), while India's 374 per million is the lowest of the ten.

Sorted bar chart of confirmed COVID-19 deaths per million people by December 31, 2023 for the 10 countries with the most deaths: Peru 6,587, the US 3,410, the UK 3,404, Brazil 3,339 and India 374

7. Programming languages people learn

Animated bar chart race of the 10 programming languages with the largest share of Google searches for tutorials, monthly from January 2005 to October 2026, with Python passing Java in April 2018 and reaching 53.9%

Python passed Java as the language people search tutorials for most in April 2018. Its share went from 3.0% in January 2005 to 53.9% in October 2026. Data: PYPL PopularitY of Programming Language index (from Google Trends).

Tip: shares add up to 100%, so a fixed x axis from 0 to 60% shows one bar growing while the others shrink.

Get the data from the PYPL PopularitY of Programming Language index (pypl.github.io, All.js,
worldwide monthly share of Google searches for "<language> tutorial"), 2005-2026
(columns: month, language, share_pct).
Make a plotly bar chart race of the top 10, one frame per month, a fixed 0-60% x axis.
- Python, Java, PHP, JavaScript, C/C++ and R in color.
- Title: the month Python passed Java.

Another way to see it: as lines, Java's fall from 29.9% to 13.0% and Python's jump in 2026 are visible at once.

Line chart of tutorial search shares for Python, Java, C/C++, JavaScript and PHP from 2005 to 2026, with Java falling from 29.9% to 13.0% and Python rising past it in 2018 and to 53.9% in 2026

8. The most populous countries

Bar chart race of the 12 most populous countries from 1950 to 2024, shown at 2024: India 1,451 million, China 1,419 million, the United States 345 million, Indonesia, Pakistan and Nigeria

India passed China as the most populous country in 2022, and in 2024 had 1,451 million people to China's 1,419 million. Nigeria climbed from 14th in 1950 to 6th. Data: UN World Population Prospects 2024 via Our World in Data.

Tip: show a top 12 instead of 10 when the climbers lower down are part of the story.

Get the data from Our World in Data (UN World Population Prospects 2024), population by
country, 1950-2024 (columns: year, country, population_m).
Make a plotly bar chart race of the top 12, 4 in-between frames per year.
- India, China, the US, Nigeria, Pakistan, Japan and Russia in color.
- Title: the year India passed China.

FAQ

bluesly
x
instagram
youtube
medium
fcaebook

Product

© 2026
Plotly. All rights reserved.
Cookie Preferences
aicpa/soc2