首页 > 解决方案 > 将高斯曲线拟合到数据

问题描述

我正在尝试将高斯曲线拟合到我拥有的一些数据,但我没有得到正确的拟合。我目前拥有的代码

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline


fig = plt.figure()
ax1 = fig.add_subplot(111)
data = x,y = np.genfromtxt('Co60_600s.csv', unpack=True, delimiter=',',skip_header=0,     usecols=(0,1))


#gaussian function
def gauss(x,A,x0,sigma):
    return A*(np.exp(-(x-x0)**2/(2*sigma)**2))

#Plotting the previous figure with gaussian curve and estimated values

A= 750
x0= 1200
sigma=10
ax1.plot(y,x)

ax1.plot(data,gauss(data, A, x0, sigma), linestyle='-', color='r', label='Estimated Best  Fit')


ax1.set_xlim(0,1400)
ax1.set_ylim(0,2000)

结果是

最终图

标签: pythonmatplotlibgraphgaussian

解决方案


推荐阅读