从Seaborn distplot获取数据点 [英] Get data points from Seaborn distplot

查看:232
本文介绍了从Seaborn distplot获取数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

sns.distplot 

绘制观测值的单变量分布.尽管如此,我不仅需要图表,还需要数据点.如何从matplotlib轴(由distplot返回)中获取数据点?

to plot a univariate distribution of observations. Still, I need not only the chart, but also the data points. How do I get the data points from matplotlib Axes (returned by distplot)?

推荐答案

您可以使用 matplotlib.patches API .例如,要获得第一行:

You can use the matplotlib.patches API. For instance, to get the first line:

sns.distplot(x).get_lines()[0].get_data()

这将返回两个numpy数组,其中包含该行的x和y值.

This returns two numpy arrays containing the x and y values for the line.

关于条,信息存储在:

sns.distplot(x).patches

您可以通过函数 patches.get_height() 访问钢筋的高度:

You can access the bar's height via the function patches.get_height():

[h.get_height() for h in sns.distplot(x).patches]

这篇关于从Seaborn distplot获取数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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