用python-lmfit高斯曲线拟合后绘制单个峰

时间:2017-02-28 15:27:18

标签: python gaussian lmfit

从这段代码中,我可以打印最终符合" out.best_fit",我现在要做的是将每个峰绘制为单独的高斯曲线,而不是全部它们合并在一条曲线上。

from pylab import *
from lmfit import minimize, Parameters, report_errors
from lmfit.models import GaussianModel, LinearModel, SkewedGaussianModel
from scipy.interpolate import interp1d
from numpy import *

fit_data = interp1d(x_data, y_data)

mod = LinearModel()
pars = mod.make_params(slope=0.0, intercept=0.0)
pars['slope'].set(vary=False)
pars['intercept'].set(vary=False)


x_peak = [278.35, 334.6, 375]
y_peak = [fit_data(x) for x in x_peak]


i = 0
for x,y in zip(x_peak, y_peak):
    sigma = 1.0
    A = y*sqrt(2.0*pi)*sigma
    prefix = 'g' + str(i) + '_'

    peak = GaussianModel(prefix=prefix)

    pars.update(peak.make_params(center=x, sigma=1.0, amplitude=A))

    pars[prefix+'center'].set(min=x-20.0, max=x+20.0) 

    pars[prefix+'amplitude'].set(min=0.0)
    mod = mod + peak
    i += 1

out = mod.fit(y_data, pars, x=x_data)

plt.figure(1)
plt.plot(x_data, y_data)
plt.figure(1)
plt.plot(x_data, out.best_fit, '--')

全球契合的情节:

Screenshot

1 个答案:

答案 0 :(得分:1)

我认为你想在健身后做到这一点:

SELECT t.pat
FROM `tab` t
JOIN `tab` r
WHERE r.pat = 'AA' -- input
  AND t.path LIKE CONCAT(r.path, '/', '%')
  AND t.has_tree = 1;

也就是说,复合模型的has_tree将返回一个字典,其中包含作为组件模型前缀的键,以及作为该组件的计算模型的值。