如何在直方图上绘制高斯图

时间:2022-06-03 14:57:43

How would I be able to plot a Gaussian on top of the histogram my code generates? Here is my code below. It works perfectly and generates a histogram but I'm struggling with adding a Gaussian curve as I've only just started using pyplot. I'm also struggling with the maths involved!

如何在我的代码生成的直方图上绘制高斯图?这是我的代码如下。它完美地工作并生成直方图,但我正在努力添加高斯曲线,因为我刚刚开始使用pyplot。我也在努力学习数学!

1 个解决方案

#1


You probably want to use numpy to generate a Gaussian, and then simply plot it on the same axes. There is a good example here:
Fitting a Gaussian to a histogram with MatPlotLib and Numpy - wrong Y-scaling?

您可能希望使用numpy生成高斯,然后将其绘制在相同的轴上。这里有一个很好的例子:使用MatPlotLib和Numpy将高斯拟合到直方图 - 错误的Y缩放?

If you actually want to automatically generate a fitted gaussian from the data, you probably need to use scipy curve_fit or leastsq functions to fit your data, similar to what's described here: gaussian fit with scipy.optimize.curve_fit in python with wrong results

如果你真的想从数据中自动生成拟合高斯,你可能需要使用scipy curve_fit或leastsq函数来拟合你的数据,类似于这里描述的:高斯拟合python中的scipy.optimize.curve_fit,结果错误

#1


You probably want to use numpy to generate a Gaussian, and then simply plot it on the same axes. There is a good example here:
Fitting a Gaussian to a histogram with MatPlotLib and Numpy - wrong Y-scaling?

您可能希望使用numpy生成高斯,然后将其绘制在相同的轴上。这里有一个很好的例子:使用MatPlotLib和Numpy将高斯拟合到直方图 - 错误的Y缩放?

If you actually want to automatically generate a fitted gaussian from the data, you probably need to use scipy curve_fit or leastsq functions to fit your data, similar to what's described here: gaussian fit with scipy.optimize.curve_fit in python with wrong results

如果你真的想从数据中自动生成拟合高斯,你可能需要使用scipy curve_fit或leastsq函数来拟合你的数据,类似于这里描述的:高斯拟合python中的scipy.optimize.curve_fit,结果错误