简体   繁体   English

如何在直方图上绘制高斯

[英]How to plot a gaussian over histogram

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. 它可以完美地工作并生成直方图,但由于我刚开始使用pyplot,因此我难以添加高斯曲线。 I'm also struggling with the maths involved! 我还在为所涉及的数学苦苦挣扎!

You probably want to use numpy to generate a Gaussian, and then simply plot it on the same axes. 您可能希望使用numpy生成高斯,然后将其绘制在相同的轴上。 There is a good example here: 这里有一个很好的例子:
Fitting a Gaussian to a histogram with MatPlotLib and Numpy - wrong Y-scaling? 使用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或minimumsq函数来拟合数据,类似于此处所述: python中的scipy.optimize.curve_fit高斯拟合结果错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM