Update
This commit is contained in:
28
script/test/test_plot_fit.py
Normal file
28
script/test/test_plot_fit.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Function fitting and peak search with mathutils facade
|
||||
"""
|
||||
from mathutils import fit_gaussian, Gaussian
|
||||
from plotutils import plot_function, plot_data
|
||||
import math
|
||||
|
||||
|
||||
def plot_fit(xdata, ydata, gauss_pars=None, title = "Fit"):
|
||||
if gauss_pars is None:
|
||||
gauss_pars = fit_gaussian(ydata, xdata)
|
||||
|
||||
(normalization, mean_value, sigma) = gauss_pars
|
||||
fitted_gaussian_function = Gaussian(normalization, mean, sigma)
|
||||
print (normalization, mean_value, sigma)
|
||||
|
||||
p = plot(None, title=title)[0]
|
||||
p.clear()
|
||||
plot_data(p, ydata, "Data", xdata=xdata, show_points = True, color=Color.BLUE)
|
||||
fit_range = frange(xdata[0],xdata[-1],float(xdata[1]-xdata[0])/100, True)
|
||||
plot_function(p, fitted_gaussian_function, "Fit", fit_range, show_points=False, color=Color.RED)
|
||||
p.setLegendVisible(True)
|
||||
p.addMarker(mean_value, None, "Mean=" + str(round(mean_value,2)), Color.LIGHT_GRAY)
|
||||
|
||||
|
||||
ydata = [0, 1,2,3,4,5,6,7,8,9,8,7,6,5,4,4,3,3,2,2,1,0]
|
||||
xdata = range(len(ydata))
|
||||
plot_fit(xdata, ydata)
|
||||
Reference in New Issue
Block a user