Sep-10-2020, 08:51 AM
Hi, Could someone please advise me how I can improve the fit of my curve such that the fit goes through all my points and resembles the graph below?
I'm trying to fit the solid line. I'm expecting the fit would be like the dashed line with no abs() in the fit code (although clearly that's not what the data is doing).
Many thanks. Cam
from scipy.optimize import curve_fit import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np m=np.array([155.9,133.7,6.4,57.9]) t=np.array([100,150,200,250]) def exponential(x, a, b): return abs(a*(1-2*np.exp(-b*x))) pars, cov = curve_fit(f=exponential, xdata=t, ydata=m, p0 = [0, 0], bounds=(-np.inf, np.inf)) fig = plt.figure() ax = fig.add_axes([0, 0, 1, 1]) ax.scatter(t, m, s=50, color='#00b3b3', label='Data') ax.plot(t, exponential(t, *pars), linestyle='--', linewidth=2, color='black')[Image: 2227418_orig.gif]
I'm trying to fit the solid line. I'm expecting the fit would be like the dashed line with no abs() in the fit code (although clearly that's not what the data is doing).
Many thanks. Cam