I am trying to first fit and then plot a demand and supply curve in the same graph. I am using Scipy to help with the curve fit. However, from the documentation, I am not able to understand how I can add the supply curve given the code below?
from scipy.optimize import curve_fit
def func(x, a, b, c):
return a * np.exp(-b * x) + c
xdata = np.linspace(0, 4, 50)
y = func(xdata, 2.5, 1.3, 0.5)
np.random.seed(1729)
y_noise = 0.2 * np.random.normal(size=xdata.size)
ydata = y + y_noise
plt.plot(xdata, ydata, 'b-', label='data')
popt1, pcov = curve_fit(func, xdata, ydata)
popt1
plt.plot(xdata, func(xdata, *popt), 'r-',
label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()
My goal is to add the black curve which is the supply surve. How would I do this assuming an inverse function of the demand curve one using the code above?