python - 将高斯曲线拟合到数据
问题描述
我正在尝试将高斯曲线拟合到我拥有的一些数据,但我没有得到正确的拟合。我目前拥有的代码
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)
结果是
解决方案
推荐阅读
- powershell - 如何在文件夹中的多个文件中搜索具有最少字符数的字符串?
- c# - MS Graph API - 启动时 System.MissingMethodException - SystemTextJsonOutputFormatter..ctor
- jgrapht - 如何使用 EdmondsKarp 最大流算法的自定义边缘实现
- c - 不理解编译器警告 - “将 unsigned into 传递给类型 unsigned int*”
- deep-learning - 为什么我的 Transformer 实现输给了 BiLSTM?
- discord.js - 机器人重启后反应角色面板停止工作 Discord.JS
- java - 如何让 InteractiveMesh 库与我的 JavaFX Mavn 项目一起使用?
- c# - 如何在 Net6 程序中使用 DbInizializer
- c# - DataSet 自动生成的代码抛出 StrongTypingException
- surveyjs - 从上一个问题中获取选项以及其他选项