I want to plot a dataset that basically shows the equilibrium point from a demand and supply curve. The graph for the demand and supply curve plots well but the equilibrium point graph doesn't seem to plot as the axes are different.
Code for the demand and supply curve.
def S(q):
return (q**2)
def D(q):
return (q - 20)**2
q = np.linspace(0, 16, 1000)
plt.plot(q, S(q), label = "Supply Curve")
plt.plot(q, D(q), label = "Demand Curve")
plt.title("Supply and Demand")
plt.legend(frameon = False)
plt.xlabel("Quantity $q$")
plt.ylabel("Price")
code for the Equilibrium price
q = sy.Symbol('q')
eq = sy.Eq(S(q), D(q))
sy.solve(eq)
plt.figure(figsize= (10, 8))#create figure and reset q to be numbers
q2 = np.linspace(0, 16, 1000)
plt.plot(q2, S(q2), label = "S Curve")#plot supply, demand, and equilibrium points
plt.plot(q2, D(q2), label = "D Curve")
plt.plot(10, 100, 'o', markersize = 14)
plt.title("Equilibrium point")#add titles and legend
plt.legend(frameon = False)
plt.xlabel("Quantity")
plt.ylabel("Price")
ax = plt.axes()#add arrow with annotation
ax.annotate('Equilibrium at (10, 100)', xy=(10,100), xytext=(10, 250), arrowprops=dict(facecolor='black'))
Expected Output
Given Output