小编Nar*_*ini的帖子

如何使用 sns.boxplot 或 sns.catplot 添加剖面线到箱线图

我需要向分类箱线图添加剖面线。我所拥有的是这样的: 在此输入图像描述

我需要的是这样的(带有中线):

在此输入图像描述

我尝试过的是这段代码:

exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise, kind="box")
bars = g.axes[0][0].patches
hatches=['//','..','xx','//','..','xx','//','..','xx']
for pat,bar in zip(hatches,bars):
    bar.set_hatch(pat)
Run Code Online (Sandbox Code Playgroud)

这只会生成第一个数字。第3-6行的想法来自这个问题。但进入第 3 行的想法axes[0][0]来自于这个问题

因为 FacetGrid 没有补丁或容器等属性,所以很难将单个图中的影线答案适应分类图,所以我无法弄清楚。

其他无效的审查问题:

python data-visualization boxplot seaborn catplot

4
推荐指数
1
解决办法
1915
查看次数

标签 统计

boxplot ×1

catplot ×1

data-visualization ×1

python ×1

seaborn ×1