Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from scipy.optimize import curve_fit
- import numpy as np
- fwhm_in = 3 # set FWHM for the artificial data - What does that it mean actually?
- sigma = fwhm_in/2/np.sqrt(2*np.log(2)) # calculate sigma - is my function normally distributed?
- xval, yval = np.genfromtxt("G3.txt", unpack=True) # I'll read datas from file so I made it by taking values as a np.array
- def fitFunc(x, x0, sigm): # this defines the fit-function
- return (sigm*np.sqrt(2*np.pi))**(-1)*np.exp(-(x-x0)**2/(2*sigm**2)) # Will I also find a fit-function for my own distribution?
- guess = (35, 60) # Corresponding degree value for high intensity is around 40 degree, so it might be between these values
- fitParams, fitCovariance = curve_fit(fitFunc, xval, yval, guess) # do the actual fit
- print(fitParams)
- print('FWHM_calc = {:.3f}'.format(fwhm_in))
- fwhm_fit = 2*fitParams[1]*np.sqrt(2*np.log(2)) # calculate the FWHM from the fitted sigma ( = fitParams[1], since fitParams[0] is the offset x0)
- print('FWHM_fit = {:.3f}'.format(fwhm_fit))
- plt.plot(xval,yval, 'r.', label='data')
- plt.plot(xval, fitFunc(xval, fitParams[0], fitParams[1]), 'k-', label='fit', linewidth = 3)
- plt.grid(True)
- plt.legend()
- ax = plt.gca()
- ax.axvline(fwhm_fit/2, color='b')
- ax.axvline(-fwhm_fit/2, color='b')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement