直方图上的非标准化高斯曲线 [英] Un-normalized Gaussian curve on histogram

查看:141
本文介绍了直方图上的非标准化高斯曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当绘制为直方图时,我具有高斯形式的数据.我想在直方图的顶部绘制高斯曲线,以查看数据的质量.我正在从matplotlib使用pyplot.我也不想标准化直方图.我可以进行标准化拟合,但是我正在寻找非标准化拟合.这里有人知道怎么做吗?

I have data which is of the gaussian form when plotted as histogram. I want to plot a gaussian curve on top of the histogram to see how good the data is. I am using pyplot from matplotlib. Also I do NOT want to normalize the histogram. I can do the normed fit, but I am looking for an Un-normalized fit. Does anyone here know how to do it?

谢谢! 阿比纳夫·库玛(Abhinav Kumar)

Thanks! Abhinav Kumar

推荐答案

例如:

import pylab as py
import numpy as np
from scipy import optimize

# Generate a 
y = np.random.standard_normal(10000)
data = py.hist(y, bins = 100)

# Equation for Gaussian
def f(x, a, b, c):
    return a * py.exp(-(x - b)**2.0 / (2 * c**2))

# Generate data from bins as a set of points 
x = [0.5 * (data[1][i] + data[1][i+1]) for i in xrange(len(data[1])-1)]
y = data[0]

popt, pcov = optimize.curve_fit(f, x, y)

x_fit = py.linspace(x[0], x[-1], 100)
y_fit = f(x_fit, *popt)

plot(x_fit, y_fit, lw=4, color="r")

这将使高斯图适合于分布,您应该使用pcov给出拟合程度的定量数字.

This will fit a Gaussian plot to a distribution, you should use the pcov to give a quantitative number for how good the fit is.

Pearson卡方检验.需要进行一些练习才能理解,但这是一个非常强大的工具.

A better way to determine how well your data is Gaussian, or any distribution is the Pearson chi-squared test. It takes some practise to understand but it is a very powerful tool.

这篇关于直方图上的非标准化高斯曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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