从 Seaborn distplot 获取数据点 [英] Get data points from Seaborn distplot
本文介绍了从 Seaborn distplot 获取数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用
sns.distplot
绘制观察的单变量分布.不过,我不仅需要图表,还需要数据点.如何从 matplotlib Axes(由 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()
这将返回两个包含行的 x 和 y 值的 numpy 数组.
This returns two numpy arrays containing the x and y values for the line.
对于条形,信息存储在:
For the bars, information is stored in:
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屋!
查看全文