【发布时间】:2021-11-05 21:52:39
【问题描述】:
我想用 txt 文件中提到的数据拟合函数 ax +blog((x-x0)/c)。 x 轴是注入电流,y 轴是 gain_X。我正在使用函数 curve_fit() ,但它不起作用并显示“未找到最佳参数:函数调用次数已达到 maxfev = 1000000”。我在下面附上了我的代码,可以使用link 查看文本文件。 你能帮我拟合数据吗?
import matplotlib.pyplot as plt
import pandas as pd
from scipy.optimize import curve_fit
import numpy as np
import scipy.optimize as opt
def func(x, a, b, c,x0):
return a*x+b*np.log((x-x0)/c)
data1 = pd.read_csv(r'C:\Users\TanviPradhan\OneDrive - EFFECT Photonics\Desktop\CD581379_A-12469303362S__GAIN_DIODE_TEST__2021-08-03_16.57.36.txt',skipinitialspace=True,comment="%")
print(data1)
#Creates one figure for the plots
fig = plt.figure(figsize=(7,14))
fig.suptitle('Wafer xx')
#Creates the subplots 1x2 plots 1st plot is 121
ax_X= fig.add_subplot(211)
plt.xlabel("Injected Current (mA)")
plt.ylabel("Measured voltage (V)")
ax_X.set_title('xx')
#ax_X.set(xlim=(0, 80), ylim=(0, 1.5))
plt.grid(True)
#add plot for each chip to total plot
ax_X.plot(data1["InjectedCurrent(mA)"],data1["GAIN_X(V)"])
x = data1["InjectedCurrent(mA)"]
y = data1["GAIN_X(V)"]
#training the data
train_x = x[:80]
train_y = y[:80]
#testing the data
test_x = x[80:]
test_y = y[80:]
plt.scatter(train_x, train_y)
plt.show()
plt.scatter(test_x, test_y)
plt.show()
#fitting_data
params,popt = curve_fit(func,x,y,maxrev=1000000)
【问题讨论】:
标签: python pandas numpy matplotlib