相互叠加显示 2 个 Seaborn 图

Ilk*_*sik 6 python plot seaborn

我想创建一个图,在其中可视化单个数据点以及不同变量的一些集中趋势度量。我想我可以在同一轴上使用seaborn stripplot(带有一些抖动)和pointplot。

import seaborn as sns
tips = sns.load_dataset("tips")
sns.set(style="white", color_codes=True)
ax = sns.stripplot(x="sex", y="total_bill", hue='smoker', data=tips,
                   split=True, jitter=True)
ax = sns.pointplot(x="sex", y="total_bill", hue='smoker', data=tips,
                   dodge=True, join=False)
Run Code Online (Sandbox Code Playgroud)

但是,当我执行此操作时,带状图中的数据值和点图中的误差线会倾斜并且不会显示在彼此之上: 示例图

如何解决此问题,以便误差线显示在抖动数据值的顶部?

Bos*_*ova 5

点图的闪避参数可以是任何值,而不仅仅是 True 或 False,它表示点之间的间隔。通过一点点试验和错误,您可以找到将两个点放置在带状图点正上方的值。我发现在这种情况下 0.4 就可以了。也许有一种更优雅的解决方案,但这是我所知道的:)

这是代码:

import seaborn as sns
tips = sns.load_dataset("tips")
sns.set(style="white", color_codes=True)
fig, ax = sns.plt.subplots()
sns.pointplot(x="sex", y="total_bill", hue='smoker', data=tips,
                   dodge=0.4, join=False, ax=ax, split = True)
sns.stripplot(x="sex", y="total_bill", hue='smoker', data=tips,
                   split=True, jitter=True, ax = ax)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 您可以对两个图使用相同的“dodge”,“sns.stripplot(..., dodge=0.3)”和“sns.pointplot(..., dodge=0.3)”。这消除了“试错”部分。 (2认同)