I want to fit a gaussian function to a data below:
data = Block[{r = RandomReal[100, 100]},
Transpose[{r, Exp[-(r - 50)^2/10] + RandomReal[.1, 100]}]];
lp = ListPlot[data, PlotRange -> All]
I fitted as follow:
FindFit[data, a E^(-(x - \[Mu])^2/(2 \[Sigma]^2)), {a, \[Mu], \[Sigma]}, x]
And the result was:
{a -> 1.02684, \[Mu] -> 50.0249, \[Sigma] -> 2.39315}
The result looks good.
I wanted to plot both the data points and the obtained gaussian function together, so I used Show with PlotRange -> All (without the option, the y-axis of the graph I got was up to 0.20):
Show[{ListPlot[data, PlotStyle -> Red],
Plot[a E^(-((x - \[Mu])^2/(2 \[Sigma]^2))) /.
{a -> 1.02684, \[Mu] -> 50.0249, \[Sigma] -> 2.39315}, {x, 1, 100}]},
PlotRange -> All]
The output was, however, not what I wanted:
You can hardly ever see the gaussian function very near the x-axis only a little.
When I put additional PlotRange -> All as an option for the Plot for the gaussian, I got the desired result:
Show[{ListPlot[data, PlotStyle -> Red],
Plot[a E^(-((x - \[Mu])^2/(2 \[Sigma]^2))) /. {a ->
1.02684, \[Mu] -> 50.0249, \[Sigma] -> 2.39315}, {x, 1, 100}, PlotRange -> All]},
PlotRange -> All]
I don't know the reason why I couldn't get the full plot of the gaussian with only the PlotRange -> All as an option for the Show?


