HOWTO · Seaborn
How to Set Marker Size in Seaborn Scatterplots
Set one marker area with `s`, map a numeric variable to marker size, or use Seaborn's `size` and `sizes` parameters for a scaled size legend.
On this page
For one marker size across a Seaborn scatterplot, pass s to sns.scatterplot; it uses Matplotlib’s scatter area units (points squared). To vary marker areas from data, pass a numeric array to s. For a Seaborn-managed mapping and legend, use size for the data variable and sizes for the display range.
Method 1: Using the s Parameter in scatterplot
Use s when every point should have the same marker area. The value is an area in points squared, so doubling it does not double the marker’s width. Increase or decrease it until points are legible without hiding one another.
Run this example:
import matplotlib.pyplot as plt
import seaborn as sns
x = [1, 2, 3, 4]
y = [2, 3, 2, 5]
area = 64
sns.scatterplot(x=x, y=y, s=area, color="teal", marker="o")
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Fixed marker area")
print(f"Marker area: {area} pt^2")
plt.close()
Marker area: 64 pt^2
The fixed s value applies to all points in this call. Add a hue mapping when color should distinguish groups; it is independent of marker area.
Method 2: Adjusting Marker Size with a Variable
To make each marker’s area represent a numeric column, pass one numeric value per row to s. Because the values are areas, scale the column to a useful range rather than using raw measurements blindly. For example, with a DataFrame named data, s=data["party_size"] * 20 supplies one area per row; tune the multiplier for your data and figure size. Keep x, y, and size values aligned by row.
Use hue="day" alongside this when color should encode a separate categorical variable. The size values should remain numeric; categorical grouping belongs in hue rather than being multiplied into s.
Method 3: Customizing Marker Sizes with Additional Parameters
Use Seaborn’s size semantic when you want Seaborn to map a data variable to marker sizes and create a corresponding legend. For example, with a DataFrame named data, call sns.scatterplot(data=data, x="total_bill", y="tip", size="size", sizes=(30, 180)). Here size names the column to map, while sizes gives the minimum and maximum marker areas in points squared. Numeric values are scaled across that range; a categorical size variable is represented with discrete levels.
You can combine size with hue for color groups and style for marker shapes. Use palette to choose colors for a hue mapping, or color for one color when no hue mapping is needed. Set marker to choose a shared marker shape. These options can make groups easier to distinguish, but keep the number of visual encodings manageable so the size legend remains readable.
Conclusion
Choose s for a fixed marker area or a numeric per-point array of areas. Choose Seaborn’s size and sizes when you want a data-driven size mapping with a size legend and controlled range. Remember that marker size refers to area, then adjust the values to keep points clear in the finished figure.
FAQ
-
How do I change the default marker size in Seaborn? Pass an area with
stosns.scatterplot, such ass=64, for one shared size. -
Can points have different sizes in one scatterplot? Yes. Pass a numeric per-row array to
s, or usesizewithsizesfor Seaborn’s mapped scale and legend. -
What does
huedo? It maps a variable to color, commonly to distinguish categories. It is separate from the marker-size mapping. -
How can I make the plot easier to read? Tune the area range, use distinct colors or marker styles only when they communicate useful groups, and label the axes. If points overlap, smaller markers or transparency can help.
-
How do I save a Seaborn scatterplot? Save the Matplotlib figure before displaying or closing it, for example with
plt.savefig("scatterplot.png", dpi=150, bbox_inches="tight")after creating the plot.