Bubble Charts
What is a bubble chart?
A bubble chart is a scatter plot where marker size carries a third variable, so a single point communicates three numbers at once:
- x axis = metric 1
- y axis = metric 2
- bubble size = metric 3 (volume/magnitude)
Add colorcolor and you’re encoding a fourth variable too — which is exactly what px.scatter(..., size=...)px.scatter(..., size=...) gives you; a bubble chart isn’t a separate chart type in Plotly, it’s a scatter plot with the sizesize argument filled in.
Example
Bubble chart
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
"sales": [120, 180, 90, 160],
"profit": [30, 45, 10, 35],
"orders": [200, 350, 120, 280],
})
fig = px.scatter(
df,
x="sales",
y="profit",
size="orders",
color="city",
hover_name="city",
title="Sales vs Profit (bubble size = orders)",
)
fig.show()Bubble chart
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
"sales": [120, 180, 90, 160],
"profit": [30, 45, 10, 35],
"orders": [200, 350, 120, 280],
})
fig = px.scatter(
df,
x="sales",
y="profit",
size="orders",
color="city",
hover_name="city",
title="Sales vs Profit (bubble size = orders)",
)
fig.show()Plotly scales bubble area (not raw radius) to the sizesize column by default, which is the perceptually correct choice — doubling a value should roughly double the visual area, not the diameter.
Tips
- Keep sizes reasonable; very large bubbles hide others — cap the biggest bubble at a sensible max area.
- Use hover tooltips (
hover_namehover_name) to reduce label clutter instead of printing every city name on the chart. - Watch out for overlap: when bubbles are close together, consider adding
opacityopacityso overlapping regions stay readable.
flowchart LR A["px.scatter(x, y)"] --> B["+ size=column
marker area encodes metric 3"] B --> C["+ color=column
hue encodes metric 4 (category)"] C --> D["Bubble chart:
4 variables, 1 point per row"]
Next
Continue to: Sunburst Charts for visualizing hierarchical data.
🧪 Try It Yourself
Exercise 1 – Turn a Scatter into a Bubble Chart
Exercise 2 – Reduce Label Clutter with hover_name
Exercise 3 – Add a Fourth Variable with Color
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
