Color the shaded area under the curve distribution plot different colors

大兔子大兔子 提交于 2020-01-15 04:34:45

问题


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.

Any idea how I can go about doing that?

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


回答1:


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


来源:https://stackoverflow.com/questions/46711019/color-the-shaded-area-under-the-curve-distribution-plot-different-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!