如何在 python 中找到直方图的包络线(连续函数)

How to find envelope (continuous function) of histogram in python

我有一个来自测量数据的直方图,我想找到这个直方图的包络线(连续函数)。你有什么建议?如何在 python 中完成?

plot_histogram_of_real_data(file_name='/home/me/data.txt'):
        plt.figure('Histogram of real data')
        data = load_measured_data(file_name)
        n, bins, patches = plt.hist(data, 30, facecolor='green', alpha=0.75)
        plt.grid()
        plt.show()

您可以使用以下几种方法之一拟合从直方图中获得的数据:

还有核密度近似:scipy.stats.gaussian_kde这是大多数统计学家的标准表示。

seaborn中,您可以为单组数据绘制sns.kdeplot,为多组数据绘制sns.violinplot。对于可能差异很大的数据,我建议使用内核密度估计,而不是从直方图中拟合您自己的某些函数。