Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 38 ยท Relational and Categorical Plots

Bubble Plots: Adding a Third Variable with Size

Create bubble plots in seaborn by mapping a numeric column to marker size, tune the size range, avoid misleading bubbles, add labels and combine with hue.

A bubble plot is a scatter plot where the size of each marker carries a third number. It is the classic way to show, say, countries by income (x), life expectancy (y) and population (area). Seaborn needs no special function: use scatterplot with size= (and sizes=), optionally with hue for a fourth variable.

Making bubbles

Python A bubble plot of simulated countries

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The plot encodes four variables: income (x, log scale), life expectancy (y), population (bubble area) and region (color). The key arguments:

  • size="population_m" maps a numeric column to marker area.
  • sizes=(30, 900) sets the smallest and largest area. Seaborn scales values linearly between these limits.
  • alpha and a white edgecolor keep overlapping bubbles legible.
  • The legend lists both the color groups and a few sample sizes.

Size encodes area, not radius

Human eyes judge a bubble by its area. Matplotlib marker sizes (s) are areas in points squared, and seaborn's sizes range is also areas, so a value twice as large looks twice as big, which is what you want. Do not map to the radius yourself, because doubling the radius quadruples the area and exaggerates differences.

Even so, readers estimate bubble size poorly. Use size for a rough "bigger or smaller" signal, and give exact numbers elsewhere (a table or labels).

Controlling the size mapping

Argument Meaning
size="col" Numeric (or ordered categorical) column controlling area
sizes=(min, max) Area limits for the smallest and largest value
size_norm=(lo, hi) Value range that maps onto the size range; values outside are clipped
size_order=[...] Order for categorical sizes
legend="brief" Show about five representative sizes

size_norm is useful for comparing figures: with the same size_norm, one value gets the same bubble in every chart.

Python size_norm keeps sizes comparable

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Because both panels use size_norm=(0, 200), a bubble for sales of 100 is the same size in each. Without it, each panel would stretch its own smallest and largest values across the whole size range, and Store B would look the same as Store A even though its sales are doubled.

Labeling bubbles

Seaborn does not label points automatically. Loop over the rows and call Matplotlib's annotate, but only for the points that matter, such as the largest or most unusual ones:

Python
for _, row in countries.nlargest(3, "population_m").iterrows():
    ax.annotate(row["region"], (row["income"], row["life_expectancy"]),
                xytext=(6, 6), textcoords="offset points")

Labeling everything produces clutter. Highlight the story and leave the rest.

When not to use bubbles

  • When the third variable is a category: use hue or style.
  • When differences are small: area changes under 20% are hard to see.
  • When there are hundreds of overlapping points: use a 2D histogram or KDE.
  • When the exact value matters: a table or a bar chart communicates it better.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which arguments create a bubble plot in seaborn?

    There is no separate bubble function; the size semantic of scatterplot does the job.
  2. 2. What does sizes=(30, 900) set?

    Values are scaled between the minimum and maximum area.
  3. 3. Why use size_norm=(0, 200) in two panels?

    A fixed normalization range makes sizes comparable across plots.
  4. 4. How should bubble size be treated by readers?

    People judge area imprecisely, so bubbles give rough size, not exact values.

Summary

  • A bubble plot is scatterplot with size= (and sizes=) mapped to a third numeric column.
  • Marker size encodes area; set the limits with sizes and keep scales consistent with size_norm.
  • Add hue for a fourth variable, alpha and edge colors for overlap.
  • Label only the interesting bubbles with annotate.
  • Bubbles show rough magnitude; use tables or labels for exact values.

Next: Line Plots with lineplot