Untitled
unknown
plain_text
9 days ago
1.4 kB
2
Indexable
Never
import matplotlib.pyplot as plt import numpy as np # Create data for the demand and supply curves P = np.linspace(0, 5, 100) Qd = 10 - 2 * P # Demand curve equation Qs = 2 + 2 * P # Supply curve equation # Equilibrium point Pe = 2 Qe = 6 # Price floor level Pf = 3.5 # Quantity demanded and supplied at the price floor Qd_floor = 10 - 2 * Pf Qs_floor = 2 + 2 * Pf # Setup figure and axis fig, ax = plt.subplots() # Plot the demand and supply curves ax.plot(Qd, P, label="Demand (Qd)", color='blue') ax.plot(Qs, P, label="Supply (Qs)", color='orange') # Mark equilibrium ax.scatter(Qe, Pe, color='red', zorder=5) ax.text(Qe - 0.5, Pe + 0.1, f"Equilibrium (Q={Qe}, P={Pe})", color='red') # Mark price floor ax.axhline(y=Pf, color='green', linestyle='--', label=f"Price Floor (P={Pf})") # Mark points for surplus ax.scatter(Qd_floor, Pf, color='purple', zorder=5) ax.scatter(Qs_floor, Pf, color='purple', zorder=5) ax.text(Qd_floor + 0.2, Pf + 0.1, f"Qd={Qd_floor}", color='purple') ax.text(Qs_floor + 0.2, Pf + 0.1, f"Qs={Qs_floor}", color='purple') # Shaded region for deadweight loss ax.fill_betweenx([0, Pf], Qd_floor, Qs_floor, color='gray', alpha=0.3, label="Deadweight Loss") # Labels and title ax.set_xlabel("Quantity") ax.set_ylabel("Price") ax.set_title("Price Floor: Surplus and Deadweight Loss") ax.legend() # Show the plot plt.grid(True) plt.show()
Leave a Comment