Bubble chart
A bubble chart is a scatter plot where marker area encodes a third number, such as population or sample size. A size legend is essential, because readers can't judge area without a reference.
When to use it
- You have three numeric variables and one of them is a magnitude (count, size, weight).
- Rough comparison of the third variable is enough.
Watch out: People judge area poorly. If the third variable needs precise comparison, use colour or a separate chart.
Ask for it in pltchat
Upload your file and type something like:
"bubble chart: GDP per capita vs life expectancy, bubble size = population"
pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.
The matplotlib code
Self-contained with example data; swap in pd.read_csv(...) or
pd.read_excel(...) for your own file.
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(4)
gdp = rng.lognormal(9.5, 0.8, 40)
life = 50 + 6 * np.log10(gdp) + rng.normal(0, 2, 40)
pop = rng.lognormal(3, 1.1, 40) # millions
fig, ax = plt.subplots(figsize=(6.4, 4))
sc = ax.scatter(gdp, life, s=pop * 3, alpha=0.5, edgecolor="k", lw=0.5)
ax.set_xscale("log")
ax.set_xlabel("GDP per capita ($, log scale)")
ax.set_ylabel("Life expectancy (years)")
handles, labels = sc.legend_elements(prop="sizes", num=4, alpha=0.5,
func=lambda s: s / 3)
ax.legend(handles, labels, title="Population (M)", loc="lower right")
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.