Hue, style, and size

Map extra columns onto color, marker, and point size.

hue maps a column onto color. style maps onto marker shape. size maps onto point size. Use them together when three extra columns would otherwise need three charts.

Goal

Color by city, change marker by product, and scale points by revenue.

Hue

df = pd.DataFrame(
    {
        "city": ["Nairobi", "Nairobi", "Mombasa", "Mombasa", "Kisumu", "Kisumu"] * 2,
        "product": ["A", "B"] * 6,
        "units": [12, 7, 9, 4, 11, 3, 10, 8, 6, 5, 14, 2],
        "price": [10.5, 22.0, 10.5, 22.0, 10.5, 22.0] * 2,
    }
)
df["revenue"] = df["units"] * df["price"]
sns.scatterplot(data=df, x="units", y="revenue", hue="city")
plt.title("Color is city")
plt.show()

Style

df = pd.DataFrame(
    {
        "city": ["Nairobi", "Nairobi", "Mombasa", "Mombasa", "Kisumu", "Kisumu"] * 2,
        "product": ["A", "B"] * 6,
        "units": [12, 7, 9, 4, 11, 3, 10, 8, 6, 5, 14, 2],
        "price": [10.5, 22.0, 10.5, 22.0, 10.5, 22.0] * 2,
    }
)
df["revenue"] = df["units"] * df["price"]
sns.scatterplot(data=df, x="units", y="revenue", hue="city", style="product")
plt.title("Marker is product")
plt.show()

Size

df = pd.DataFrame(
    {
        "city": ["Nairobi", "Nairobi", "Mombasa", "Mombasa", "Kisumu", "Kisumu"] * 2,
        "product": ["A", "B"] * 6,
        "units": [12, 7, 9, 4, 11, 3, 10, 8, 6, 5, 14, 2],
        "price": [10.5, 22.0, 10.5, 22.0, 10.5, 22.0] * 2,
    }
)
df["revenue"] = df["units"] * df["price"]
sns.scatterplot(
    data=df,
    x="units",
    y="price",
    hue="city",
    size="revenue",
    sizes=(40, 200),
)
plt.title("Size is revenue")
plt.show()

sizes=(40, 200) sets the smallest and largest marker in points.

Pitfall

Too many channels at once make the plot hard to read. Prefer hue plus one of style or size, then facet if you still need another split.