I want to fit the function ax +blog((x-x0)/c) with data mentioned in the txt file. The x-axis is the injected current and y axis is the gain_X. I was using the function curve_fit() , but it does not works and says "Optimal parameters not found: Number of calls to function has reached maxfev = 1000000". I have attached my code below and the text file can be viewed with the link. Can you help me in fitting the data?
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)
