为曲线分布图下方的阴影区域着色不同颜色 [英] Color the shaded area under the curve distribution plot different colors

查看:46
本文介绍了为曲线分布图下方的阴影区域着色不同颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using seaborn's kdeplot to draw the distribution of my data.

sns.kdeplot(data['numbers'], shade=True)

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

I want to divide the shaded area under the line into three parts, showing the "high" percentile and the "low" percentile. It would be ideal if I can color the shaded area with three different colors.

知道我该怎么做吗?

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

I want it to look something like the below where I can decide the cutoff value between the colors.

推荐答案

所以我想出了如何去做.我会从 seaborn 图中检索 x 和 y 数组,然后使用 fill_between 在曲线下着色.

So I figured out how to do it. I would retrieve and x and y arrays from the seaborn plot, then use fill_between to color under the curve.

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')

这篇关于为曲线分布图下方的阴影区域着色不同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆