我如何在Seaborn中的catplot上显示kind="swarm"和kind="point"?

4
我正在尝试在Seaborn中显示同时包含均值和误差(kind="point")以及单个数据点(kind="swarm")的catplot叠加。
我有以下代码:
sns.catplot(x="Variable_A", y="Dependent_Variable", col="Variable_B", data=LRP_df, kind="swarm", color = "black")

sns.catplot(x="Variable_A", y="Dependent_Variable", col="Variable_B", data=LRP_df, kind="point", color = "red")

sns.despine()

这将分别生成两个图:

调用catplot函数的结果

我该如何使这两个图放在同一坐标轴上?

谢谢!

1个回答

3
使用面板网格,可以通过使用map_dataframe()指定每个网格来叠加每个网格。这个官方参考文献中的示例已经被修改过了。数据基于样本数据。
import seaborn as sns

sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")

g = sns.FacetGrid(exercise, col="kind")
g.map_dataframe(sns.stripplot, x="time", y="pulse", color="black")
g.map_dataframe(sns.pointplot, x="time", y="pulse", color="red")
g.set_axis_labels("time", "pulse")

enter image description here


如果我的回答对您有帮助,请考虑接受它作为正确的答案。 - r-beginners

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