This started out as a way to make sure I understood the numpy array slicing methods, and builds on my previous post about using scipy to fit data. I define a 3 parameter exponential decay

add some gaussian noise, and then use scipy to get the best fit as well as the covariance matrix. My understanding is that the square root of the diagonal elements gives me the 1 uncertainty on the corresponding fit parameter. So I then use the uncertainties on to compute all 8 possible effective parameter values and their corresponding fit arrays.

I then use numpy to find the standard deviation of the 8 different fit values at each x, and use this as the uncertainty on the fit at a given x. Once I have this array of fit uncertainties, I plot the best fit curve, the fit curve, the fit curve, and use the matplotlib plot.bar( ) function to plot the bars.

In any case, here is the script: CurveFitting.py , and here is an iPythonNotebook with some exposition: CurveFitWith1SigmaBand.ipynb .

Here is the final plot: (click on plot to see .pdf version)

## About PaulNakroshis

Professor of Physics at the University of Southern Maine.

Hello, I would like to know if i can use this image in teaching material to discuss scatter graphs and best fitting?

Yes you are welcome to.

-p