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

18

enter image description here

我有一段生成图表的代码:

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)

如何更改标记大小?

size=20 行为奇怪,似乎会缩放绘图区域而不是更改标记大小。我收到以下警告:

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


1
你对“怪异”的定义是什么?相比之下是什么?你期望得到什么?你得到了什么?你应该提供一些输入数据(随机生成的就可以)+一些示例代码+带有大小值的图形屏幕截图。 - LoneWanderer
@ImportanceOfBeingernest 指出您可能使用较旧的 Python/Seaborn/Matplotlib 版本。您也应该提供它们。 - LoneWanderer
奇怪的意思是:它会改变绘图区域的大小,我认为,我得到了一个巨大的图表,上面有小点,而不是大标记。我有最新的seaborn版本。 - Mark Izraelson
3个回答

19

用 s 替代 size。默认 s 是 5。

示例:

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


5

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

解决方法

从查看源代码中,我发现在 sns.stripplot 中 's' 是 'size' 的别名,因此以下操作可以按您期望的方式工作:

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)

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

size : float, optional

标记的直径,以点为单位。(尽管使用plt.scatter绘制点,但此处的size参数采用“正常”标记大小,而不是像plt.scatter那样的大小^2)。

因此,size=20似乎是一个完全有效的参数,可提供给catplot。或者任何其他适合您需求的值。
从上面提供的seaborn文档页面复制代码和屏幕...
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

使用 size=8 在此输入图像描述


你使用的seaborn版本与OP不同,因此它对你有效。 - ImportanceOfBeingErnest
它在sns.stripplot中有效,但在sns.catplot(kind ='strip')中无效。 - Mark Izraelson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接