I want to fit my data with a piecewise function that I have shown below, The whole graph is a semilogarithmic graph, and I want to fit it with two different logarithmic functions that I have shown in different colors (purple and red are drawn with my hand). The problem is that it doesn't work, and I don't know what I'm doing wrong. I will post the mini-code that I have summarized.
import numpy as np
from scipy.optimize import curve_fit
def func_stuck(t, a, b, c, d, e , f): # x-shifted log
y = np.piecewise(t, [t < 100, t >= 100],
[lambda t:a*np.log(t + b)+c, lambda t:d*np.log(t + e)+f])
return y
plt.semilogx(sensor_array__[0],sensor_array__[1])
popt, pcov = curve_fit(func_stuck,sensor_array__[0], sensor_array__[1],maxfev=100000000)
function_x = np.linspace(0.1 , 1200, 1200)
fitted_y = np.asarray(popt[0]*np.log(function_x + popt[1])+popt[2]+popt[3]*np.log(function_x + popt[4])+popt[5])
plt.semilogx(function_x,fitted_y)
what I get:
what I want to get:
my second attempt give me this one:
But still not the one that I need.