Skip to content

scatterplot assigns incorrect dot size when size has only two unique values (0 and another number) #3834

Open
@136s

Description

@136s

Description

When using sns.scatterplot with the size parameter, if the unique values in size are only 0 and one other number, the size assigned to 0 is unexpectedly large. This issue does not occur when the size list includes more than two unique nonzero values.

Steps to reproduce

import sys
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

print(f"Python: {sys.version}")
print(f"matplotlib: {plt.matplotlib.__version__}")
print(f"pandas: {pd.__version__}")
print(f"seaborn: {sns.__version__}")


def plot_dot(val: list):
    _, ax = plt.subplots(figsize=(2, 2))
    data = pd.DataFrame({"X": ["x1", "x2", "x1", "x2"], "Y": ["y1", "y1", "y2", "y2"], "size": val})
    g = sns.scatterplot(data=data, x="X", y="Y", size="size", ax=ax)
    g.legend(loc="upper left", bbox_to_anchor=(1.05, 1.0))
    g.title.set_text(f"size={val}")


plot_dot([0, 0, 1, 1])  # 0 appears abnormally large
plot_dot([None, 0, 1, 1])  # 0 appears abnormally large
plot_dot([0, 0, 1, 2])  # 0 appears correctly
plot_dot([1, 1, 2, 2])  # non zero values appears correctly

Observed behavior

Python: 3.13.2 | packaged by conda-forge | (main, Feb 17 2025, 14:02:48) [Clang 18.1.8 ]
matplotlib: 3.10.1
numpy: 2.2.4
pandas: 2.2.3
seaborn: 0.13.2

Image
Image
Image
Image

Expected behavior

  • The dots for 0 should appear small and not disproportionately large, regardless of whether size contains only two unique values.

Additional information

  • This issue persists even when explicitly setting sizes=(10, 200).
  • The problem does not occur when there are more than two unique values in size.
  • A workaround is to include additional unique values in size, but this should not be necessary.

Would appreciate any insights on whether this is an intended behavior or a bug in size scaling. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions