问题
I have a program that builds a histogram chart and I want to add a bell curve that represents the ideal curve based on the goal I got from engineering.
here is a snapshot to give you an idea of what im working with.

I formatted the seconds to represent hh:mm:ss.
In this example:
bins: 20
the goal: 672 seconds
min: 120 seconds
max: 1200 seconds
How can I plot the ideal curve for the criteria above?
the red line will eventually be curved once I can figure this out.
回答1:
How do you define "ideal curve" here? If you want to use a Gaussian bell curve you need to fit a curve of form f(t)=a*Exp(-(t-b)^2/2c^2)+d
to your data using a nonlinear curve-fitting algorithm (Levenberg-Marquardt, Nelder-Mead-Simplex are popular ones).
While it's fun to write these algorithms yourself they involve a lot of math. So I would advice you to find suitable libraries (LMA is one I can think from the top of my head).
Or you can refer to Numerical Recipies which covers this topic with a lot of code examples.
What you need to do yourself is finding suitable starting parameters for the fit from your data. In the case of the Gaussian curve that is not all too hard (a
is the amplitude, pretty much the difference between highest and lowest y-value, b
is the x-offset of the maximum, c
is a measure of width of the curve and can be chosen relativly freely if the other parameters are initialized properly, d
is the y-baseline of your data, for example the lowest value of your set).
With the fit you then get the parameters a-d in the above formula for the bell curve that best describes your data. Use these parameters to calculate a bunch of y-points in your histogramms interval (50 or so) and plot them in the red line-series.
As an example of what such a fit result looks like I made one using a non-linear-fit in Origin on made-up data. Notice the results for the 4 parameters of the curve (named a little differently here).

回答2:
By "ideal" curve, I'll assume you mean a Gaussian density. If that's not what you mean, you'll have to update the problem statement to say clearly what you mean.
Given that, just find the mean and standard deviation of the data (preferably before binning, although afterward is OK; I doubt if it makes much difference) and plot a Gaussian density (p(x) = exp(-(1/2) * ((x - mu)/sigma)^2)/(sigma * sqrt(2 pi))) where mu = mean and sigma = std deviation. I assume that you can make a list of points and plot them for any given formula.
来源:https://stackoverflow.com/questions/20961511/how-to-make-a-bell-curve-in-vb-net