How to change marker size in seaborn.catplot

Viewed 12110

enter image description hereSo I have this code which generates a plot:

g=sns.catplot(data=public, x="age", y="number", col="species", kind="strip",
              jitter=True, order=order,
              palette=palette, alpha=0.5,linewidth=3,height=6, aspect=0.7)

How to I change markers size?

size=20 acts weird and seems to zoom the plot area instead of changing markers size. And i get:

'.conda-envs/py3/lib/python3.5/site-packages/seaborn/categorical.py:3692: UserWarning: The size paramter has been renamed to height; please update your code. warnings.warn(msg, UserWarning'

3 Answers

Use s instead of size. the default s is 5.

Example:

sns.catplot(x = "time",
       y = "total_bill",
        s = 20,
       data = tips)

enter image description here

sns.catplot(x = "time",
       y = "total_bill",
        s = 1,
       data = tips)

enter image description here

There is a conflict between the parameter 'size' in sns.stripplot and the deprecated 'size' of sns.catplot, so when you pass 'size' to the latter, it overrides the 'height' parameter and shows the warning message you saw.

Workaround

From looking inside the source code, I've found that 's' is an alias of 'size' in sns.stripplot, so the following works as you expected:

g=sns.catplot(data=public, x="age", y="number", col="species", kind="strip",
              jitter=True, order=order, s=20,
              palette=palette, alpha=0.5, linewidth=3, height=6, aspect=0.7)

According catplot doc https://seaborn.pydata.org/generated/seaborn.catplot.html the underlying stripyou are using is documented here: https://seaborn.pydata.org/generated/seaborn.stripplot.html#seaborn.stripplot

Quoting:

size : float, optional

Diameter of the markers, in points. (Although plt.scatter is used to draw the points, the size argument here takes a “normal” markersize and not size^2 like plt.scatter).

So size=20 seems to be a perfectly valid parameter to give to catplot. Or any other value that suits your needs.

Copy pasta code with screens from seaborn documentation pages provided above...

import seaborn as sns

sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x=tips["total_bill"])

ax = sns.stripplot("day", "total_bill", "smoker", data=tips, palette="Set2", size=20, marker="D", edgecolor="gray",
                   alpha=.25)

enter image description here

with size=8 enter image description here

Related