为曲线分布图下方的阴影区域着色不同颜色

BKS*_*BKS 3 python matplotlib seaborn

我正在使用 seaborn 的 kdeplot 来绘制我的数据分布。

sns.kdeplot(data['numbers'], shade=True)
Run Code Online (Sandbox Code Playgroud)

我想将线下的阴影区域分成三部分,分别显示“高”百分位数和“低”百分位数。如果我可以用三种不同的颜色为阴影区域着色,那将是理想的。

知道我该怎么做吗?

我希望它看起来像下面这样我可以决定颜色之间的截止值。

在此处输入图片说明

BKS*_*BKS 6

所以我想出了怎么做。我会从 seaborn 图中检索 x 和 y 数组,然后用于fill_between在曲线下着色。

points = sns.kdeplot(data['numbers'], shade=True).get_lines()[0].get_data()

x = points[0]
y = points[1]

plt.fill_between(x,y, where = x >=0.75, color='r')
plt.fill_between(x,y, where = x <=0.1, color='g')
plt.fill_between(x,y, where = (x<=0.75) & (x>=0.1), color='y')
Run Code Online (Sandbox Code Playgroud)