如何在 seaborn.catplot 中更改标记大小

Mar*_*son 9 markers python-3.x seaborn

在这里输入图像描述所以我有这个生成图的代码:

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)
Run Code Online (Sandbox Code Playgroud)

如何更改标记大小?

size=20行为怪异,似乎缩放绘图区域而不是更改标记大小。我得到:

'.conda-envs/py3/lib/python3.5/site-packages/seaborn/categorical.py:3692:UserWarning:size参数已重命名为height;请更新您的代码。警告。警告(味精,用户警告'

Wes*_*hua 7

使用 s 而不是大小。默认 s 是 5。

例子:

sns.catplot(x = "time",
       y = "total_bill",
        s = 20,
       data = tips)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

sns.catplot(x = "time",
       y = "total_bill",
        s = 1,
       data = tips)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


Sho*_*alt 5

sns.stripplot中的参数“size”和已弃用的“size”之间存在冲突sns.catplot,因此当您将“size”传递给后者时,它会覆盖“height”参数并显示您看到的警告消息。

解决方法

通过查看源代码,我发现 's' 是 'size' 中的别名sns.stripplot,因此以下内容按您的预期工作:

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)
Run Code Online (Sandbox Code Playgroud)


Lon*_*rer 0

根据 catplot 文档https://seaborn.pydata.org/ generated/seaborn.catplot.html您正在使用的底层strip记录在此处: https: //seaborn.pydata.org/ generated/seaborn.stripplot.html#seaborn.stripplot

\n

引用:

\n
\n

尺寸:浮动,可选

\n

标记的直径(以磅为单位)。(虽然plt.scatter用于绘制点,但size这里的参数采用 \xe2\x80\x9cnormal\xe2\x80\x9d 标记大小,而不是像 size^2plt.scatter)。

\n
\n

所以size=20似乎是给 catplot 一个完全有效的参数。或者任何其他适合您需求的值。

\n

从上面提供的seaborn文档页面中复制带有屏幕的面食代码...

\n
import seaborn as sns\n\nsns.set(style="whitegrid")\ntips = sns.load_dataset("tips")\nax = sns.stripplot(x=tips["total_bill"])\n\nax = sns.stripplot("day", "total_bill", "smoker", data=tips, palette="Set2", size=20, marker="D", edgecolor="gray",\n                   alpha=.25)\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n

size=8\n在此输入图像描述

\n