curvefit in matplotlib code example
Example: show fit on plot python
from scipy.optimize import curve_fit
def exponential(x, a, b):
return a*np.exp(b*x)
x_dummy = np.linspace(start=5, stop=15, num=50)
y_dummy = exponential(x_dummy, 0.5, 0.5)
ax.scatter(x_dummy, y_dummy, s=20, color='#00b3b3', label='Data')
pars, cov = curve_fit(f=exponential, xdata=x_dummy, ydata=y_dummy, p0=[0, 0], bounds=(-np.inf, np.inf))
ax.plot(x_dummy, exponential(x_dummy, *pars), linestyle='--', linewidth=2, color='black')