0

当使用 catplot 的“col”功能时,我希望将 barplot 与 seaborn 中的 swarmplot 结合起来。

我知道这个问题之前在barplot 上的 seaborn overlay swarmplot中被问过,但这个解决方案对我不起作用。我想制作多个子图(使用“col”)。因此,当我尝试他们的解决方案时,swarmplot 的所有数据点都绘制在最后一个子图上,而不是相应的子图上:

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.catplot(x="sex", y="total_bill",
                hue="smoker", col="time",
                data=tips, kind="bar",
                height=4, aspect=.7);
sns.swarmplot(x="sex", y="total_bill", data=tips,dodge=True)

结果

我还尝试了以下方法,使用 map_dataframe:

g = sns.catplot(x="sex", y="total_bill",
                hue="smoker", col="time",
                data=tips, kind="bar",
                height=4, aspect=.7);
g.map_dataframe(sns.swarmplot,"sex","total_bill","smoker")

但是在这里,结果看起来也不正确(对于每个条,我想要那里的对应点)

如何获取相应子图和条形图上的数据点?颜色可以是黑色,但我只想了解点的分布。

4

0 回答 0