my-markdown-library 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/F24LS_md/ Lecture 4 - Public.md +347 -0
- data/F24LS_md/Lecture 1 - Introduction and Overview.md +327 -0
- data/F24LS_md/Lecture 10 - Development_.md +631 -0
- data/F24LS_md/Lecture 11 - Econometrics.md +345 -0
- data/F24LS_md/Lecture 12 - Finance.md +692 -0
- data/F24LS_md/Lecture 13 - Environmental Economics.md +299 -0
- data/F24LS_md/Lecture 15 - Conclusion.md +272 -0
- data/F24LS_md/Lecture 2 - Demand.md +349 -0
- data/F24LS_md/Lecture 3 - Supply.md +329 -0
- data/F24LS_md/Lecture 5 - Production C-D.md +291 -0
- data/F24LS_md/Lecture 6 - Utility and Latex.md +440 -0
- data/F24LS_md/Lecture 7 - Inequality.md +607 -0
- data/F24LS_md/Lecture 8 - Macroeconomics.md +704 -0
- data/F24LS_md/Lecture 8 - Macro.md +700 -0
- data/F24LS_md/Lecture 9 - Game Theory_.md +436 -0
- data/F24LS_md/summary.yaml +105 -0
- data/F24Lec_MD/LecNB_summary.yaml +206 -0
- data/F24Lec_MD/lec01/lec01.md +267 -0
- data/F24Lec_MD/lec02/Avocados_demand.md +425 -0
- data/F24Lec_MD/lec02/Demand_Steps_24.md +126 -0
- data/F24Lec_MD/lec02/PriceElasticity.md +83 -0
- data/F24Lec_MD/lec02/ScannerData_Beer.md +171 -0
- data/F24Lec_MD/lec02/demand-curve-Fa24.md +213 -0
- data/F24Lec_MD/lec03/3.0-CubicCostCurve.md +239 -0
- data/F24Lec_MD/lec03/3.1-Supply.md +274 -0
- data/F24Lec_MD/lec03/3.2-sympy.md +332 -0
- data/F24Lec_MD/lec03/3.3a-california-energy.md +120 -0
- data/F24Lec_MD/lec03/3.3b-a-really-hot-tuesday.md +121 -0
- data/F24Lec_MD/lec04/lec04-CSfromSurvey-closed.md +335 -0
- data/F24Lec_MD/lec04/lec04-CSfromSurvey.md +331 -0
- data/F24Lec_MD/lec04/lec04-Supply-Demand-closed.md +519 -0
- data/F24Lec_MD/lec04/lec04-Supply-Demand.md +514 -0
- data/F24Lec_MD/lec04/lec04-four-plot-24.md +34 -0
- data/F24Lec_MD/lec04/lec04-four-plot.md +34 -0
- data/F24Lec_MD/lec05/Lec5-Cobb-Douglas.md +131 -0
- data/F24Lec_MD/lec05/Lec5-CobbD-AER1928.md +283 -0
- data/F24Lec_MD/lec06/6.1-Sympy-Differentiation.md +253 -0
- data/F24Lec_MD/lec06/6.2-3D-utility.md +287 -0
- data/F24Lec_MD/lec06/6.3-QuantEcon-Optimization.md +399 -0
- data/F24Lec_MD/lec06/6.4-latex.md +138 -0
- data/F24Lec_MD/lec06/6.5-Edgeworth.md +269 -0
- data/F24Lec_MD/lec07/7.1-inequality.md +283 -0
- data/F24Lec_MD/lec07/7.2-historical-inequality.md +237 -0
- data/F24Lec_MD/lec08/macro-fred-api.md +313 -0
- data/F24Lec_MD/lec09/lecNB-prisoners-dilemma.md +88 -0
- data/F24Lec_MD/lec10/Lec10.2-waterguard.md +401 -0
- data/F24Lec_MD/lec10/lec10.1-mapping.md +199 -0
- data/F24Lec_MD/lec11/11.1-slr.md +305 -0
- data/F24Lec_MD/lec11/11.2-mlr.md +171 -0
- data/F24Lec_MD/lec12/Lec12-4-PersonalFinance.md +590 -0
- data/F24Lec_MD/lec12/lec12-1_Interest_Payments.md +267 -0
- data/F24Lec_MD/lec12/lec12-2-stocks-options.md +235 -0
- data/F24Lec_MD/lec13/Co2_ClimateChange.md +139 -0
- data/F24Lec_MD/lec13/ConstructingMAC.md +213 -0
- data/F24Lec_MD/lec13/EmissionsTracker.md +170 -0
- data/F24Lec_MD/lec13/KuznetsHypothesis.md +219 -0
- data/F24Lec_MD/lec13/RoslingPlots.md +217 -0
- data/F24Lec_MD/lec15/vibecession.md +485 -0
- data/F24Textbook_MD/00-intro/index.md +292 -0
- data/F24Textbook_MD/01-demand/01-demand.md +152 -0
- data/F24Textbook_MD/01-demand/02-example.md +131 -0
- data/F24Textbook_MD/01-demand/03-log-log.md +284 -0
- data/F24Textbook_MD/01-demand/04-elasticity.md +248 -0
- data/F24Textbook_MD/01-demand/index.md +15 -0
- data/F24Textbook_MD/02-supply/01-supply.md +203 -0
- data/F24Textbook_MD/02-supply/02-eep147-example.md +86 -0
- data/F24Textbook_MD/02-supply/03-sympy.md +138 -0
- data/F24Textbook_MD/02-supply/04-market-equilibria.md +204 -0
- data/F24Textbook_MD/02-supply/index.md +16 -0
- data/F24Textbook_MD/03-public/govt-intervention.md +73 -0
- data/F24Textbook_MD/03-public/index.md +10 -0
- data/F24Textbook_MD/03-public/surplus.md +351 -0
- data/F24Textbook_MD/03-public/taxes-subsidies.md +282 -0
- data/F24Textbook_MD/04-production/index.md +15 -0
- data/F24Textbook_MD/04-production/production.md +178 -0
- data/F24Textbook_MD/04-production/shifts.md +296 -0
- data/F24Textbook_MD/05-utility/budget-constraints.md +166 -0
- data/F24Textbook_MD/05-utility/index.md +15 -0
- data/F24Textbook_MD/05-utility/utility.md +136 -0
- data/F24Textbook_MD/06-inequality/historical-inequality.md +253 -0
- data/F24Textbook_MD/06-inequality/index.md +15 -0
- data/F24Textbook_MD/06-inequality/inequality.md +226 -0
- data/F24Textbook_MD/07-game-theory/bertrand.md +257 -0
- data/F24Textbook_MD/07-game-theory/cournot.md +333 -0
- data/F24Textbook_MD/07-game-theory/equilibria-oligopolies.md +96 -0
- data/F24Textbook_MD/07-game-theory/expected-utility.md +61 -0
- data/F24Textbook_MD/07-game-theory/index.md +19 -0
- data/F24Textbook_MD/07-game-theory/python-classes.md +340 -0
- data/F24Textbook_MD/08-development/index.md +35 -0
- data/F24Textbook_MD/09-macro/CentralBanks.md +101 -0
- data/F24Textbook_MD/09-macro/Indicators.md +77 -0
- data/F24Textbook_MD/09-macro/fiscal_policy.md +36 -0
- data/F24Textbook_MD/09-macro/index.md +14 -0
- data/F24Textbook_MD/09-macro/is_curve.md +76 -0
- data/F24Textbook_MD/09-macro/phillips_curve.md +70 -0
- data/F24Textbook_MD/10-finance/index.md +10 -0
- data/F24Textbook_MD/10-finance/options.md +178 -0
- data/F24Textbook_MD/10-finance/value-interest.md +60 -0
- data/F24Textbook_MD/11-econometrics/index.md +16 -0
- data/F24Textbook_MD/11-econometrics/multivariable.md +218 -0
- data/F24Textbook_MD/11-econometrics/reading-econ-papers.md +25 -0
- data/F24Textbook_MD/11-econometrics/single-variable.md +483 -0
- data/F24Textbook_MD/11-econometrics/statsmodels.md +58 -0
- data/F24Textbook_MD/12-environmental/KuznetsHypothesis-Copy1.md +187 -0
- data/F24Textbook_MD/12-environmental/KuznetsHypothesis.md +187 -0
- data/F24Textbook_MD/12-environmental/MAC.md +254 -0
- data/F24Textbook_MD/12-environmental/index.md +36 -0
- data/F24Textbook_MD/LICENSE.md +11 -0
- data/F24Textbook_MD/intro.md +26 -0
- data/F24Textbook_MD/references.md +25 -0
- data/F24Textbook_MD/summary.yaml +414 -0
- metadata +155 -0
@@ -0,0 +1,331 @@
|
|
1
|
+
---
|
2
|
+
title: "lec04-CSfromSurvey"
|
3
|
+
type: lecture-notebook
|
4
|
+
week: 4
|
5
|
+
source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec04/lec04-CSfromSurvey.ipynb"
|
6
|
+
---
|
7
|
+
|
8
|
+
<table style="width: 100%;">
|
9
|
+
<tr style="background-color: transparent;"><td>
|
10
|
+
<img src="https://data-88e.github.io/assets/images/blue_text.png" width="250px" style="margin-left: 0;" />
|
11
|
+
</td><td>
|
12
|
+
<p style="text-align: right; font-size: 10pt;"><strong>Economic Models</strong>, Fall 2024<br>
|
13
|
+
Dr. Eric Van Dusen <br>
|
14
|
+
Kidong Kim</p></td></tr>
|
15
|
+
</table>
|
16
|
+
|
17
|
+
# Lecture 4: Demand Survey and Surplus #
|
18
|
+
|
19
|
+
The idea for this demo is to use the student's demand curve to motivate the concept of surplus.
|
20
|
+
|
21
|
+
```python
|
22
|
+
from datascience import *
|
23
|
+
import numpy as np
|
24
|
+
import pandas as pd
|
25
|
+
import matplotlib.pyplot as plt
|
26
|
+
import matplotlib.patches as patches
|
27
|
+
%matplotlib inline
|
28
|
+
|
29
|
+
import sympy
|
30
|
+
solve = lambda x,y: sympy.solve(x-y)[0] if len(sympy.solve(x-y))==1 else "Not Single Solution"
|
31
|
+
|
32
|
+
from ipywidgets import interact, interactive, fixed, interact_manual
|
33
|
+
import ipywidgets as widgets
|
34
|
+
from IPython.display import display
|
35
|
+
import warnings
|
36
|
+
warnings.filterwarnings("ignore")
|
37
|
+
```
|
38
|
+
|
39
|
+
## Section 1: Market Demand and Consumer Surplus
|
40
|
+
|
41
|
+
Let's start off with the demand from a student demand survey:
|
42
|
+
- We had 4 "goods" and a range of prices available for each good
|
43
|
+
- Students made bids on their willingness to pay for each of the 4 goods
|
44
|
+
- The dataset for Fall 2022 has ~100 observations
|
45
|
+
- This dataset has been exported and we read it in below:
|
46
|
+
|
47
|
+
```python
|
48
|
+
# sheet_id = "1jzgX74fgWo91Dyv7SbD4AmSFvUN5APc79BaOENpsyv8"
|
49
|
+
# sheet_name = "Form1"
|
50
|
+
# url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
|
51
|
+
|
52
|
+
sheet_id = "1jzgX74fgWo91Dyv7SbD4AmSFvUN5APc79BaOENpsyv8"
|
53
|
+
sheet_name = "Form1"
|
54
|
+
url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
|
55
|
+
|
56
|
+
|
57
|
+
df_demand=pd.read_csv(url)
|
58
|
+
|
59
|
+
DemandTable = Table.from_df(df_demand)
|
60
|
+
DemandTable = DemandTable.drop('Timestamp')
|
61
|
+
DemandTable
|
62
|
+
```
|
63
|
+
|
64
|
+
```python
|
65
|
+
for i in DemandTable.labels:
|
66
|
+
DemandTable.ihist(i, bins=7);
|
67
|
+
```
|
68
|
+
|
69
|
+
**Let's focus on the burritos first.** How many people are willing to buying a gourment burrito at any given price?
|
70
|
+
We can assume that a person would be willing to buy the good at a price less than their bid price.
|
71
|
+
|
72
|
+
```python
|
73
|
+
BurritosTable = DemandTable.select('Burrito')
|
74
|
+
BurritosTable
|
75
|
+
```
|
76
|
+
|
77
|
+
```python
|
78
|
+
# Count how many people are in each answer pool
|
79
|
+
BurritosTable.group("Burrito")
|
80
|
+
```
|
81
|
+
|
82
|
+
```python
|
83
|
+
# Create a bar plot
|
84
|
+
table = BurritosTable.group("Burrito")
|
85
|
+
|
86
|
+
def plot_histogram(data, bins, title="Title", x_label = "Price", y_label = "Count"):
|
87
|
+
plt.bar(bins, data, edgecolor="brown", align="center", width = 2)
|
88
|
+
plt.title(title)
|
89
|
+
plt.xlabel(x_label)
|
90
|
+
plt.ylabel(y_label)
|
91
|
+
plt.show()
|
92
|
+
return
|
93
|
+
|
94
|
+
burrito_bins = table.column(0) # Select column using method call
|
95
|
+
burrito_data = table['count'] # Select column using indexing
|
96
|
+
burrito_title = "Demand of Burritos according to different prices"
|
97
|
+
|
98
|
+
plot_histogram(burrito_data, burrito_bins, burrito_title)
|
99
|
+
```
|
100
|
+
|
101
|
+
In the visualization above, the height of each bar isn't quite right - someone who is willing to pay \\$10 for a burrito will also pay \\$2.5 for the same burrito.
|
102
|
+
|
103
|
+
```python
|
104
|
+
Qdemand = np.flip(np.cumsum(np.flip(BurritosTable.group("Burrito").column("count"))))
|
105
|
+
Qdemand
|
106
|
+
```
|
107
|
+
|
108
|
+
```python
|
109
|
+
DemandBurr= Table().with_columns([
|
110
|
+
'priceBurr', [2.5, 5, 7.5, 10.00, 12.5, 15,17.5, 20], # those are the prices
|
111
|
+
'Qdemand', Qdemand
|
112
|
+
])
|
113
|
+
DemandBurr
|
114
|
+
```
|
115
|
+
|
116
|
+
```python
|
117
|
+
burrito_Qdemand_bins = DemandBurr.column('priceBurr') # Select column using method call
|
118
|
+
burrito_Qdemand_data = DemandBurr['Qdemand'] # Select column using indexing
|
119
|
+
burrito_Qdemand_title = "Quantity demanded of Burritos with different prices"
|
120
|
+
Qdemand_x_label = "Price of Burrito"
|
121
|
+
Qdemand_y_label = "Quantity demanded"
|
122
|
+
|
123
|
+
plot_histogram(burrito_Qdemand_data, burrito_Qdemand_bins, burrito_Qdemand_title, Qdemand_x_label, Qdemand_y_label)
|
124
|
+
```
|
125
|
+
|
126
|
+
### Let's take a look at this table and think about the Consumer Surplus
|
127
|
+
|
128
|
+
First, let's sort the table from the most expensive burritos to the least expensive ones.
|
129
|
+
|
130
|
+
Then, if the price is \$10, how many people are willing to pay more than the price? These people would be getting a **surplus** by only having to pay a cheaper price than the one they would be willing to pay.
|
131
|
+
|
132
|
+
```python
|
133
|
+
DemandBurr.sort("priceBurr", descending = True)
|
134
|
+
```
|
135
|
+
|
136
|
+
It looks like
|
137
|
+
- 52 people would have been willing to pay up to \\$12.5
|
138
|
+
- 25 people would have been willing to pay up to \\$15.0
|
139
|
+
- 8 person would have been willing to pay up to \\$17.5
|
140
|
+
- 4 people would have been willing to pay up to \\$20.0
|
141
|
+
|
142
|
+
Let's add up these values
|
143
|
+
|
144
|
+
```python
|
145
|
+
CS_counting = 52*(12.5-10)+25*(15-10)+8*(17.5-10)+4*(20-10)
|
146
|
+
print('The consumer surplus from counting consumers is', CS_counting)
|
147
|
+
```
|
148
|
+
|
149
|
+
```python
|
150
|
+
# calculate the total consumer surplus given a demand table and the price of the good
|
151
|
+
def consumer_surplus(demand_table, price):
|
152
|
+
|
153
|
+
# only people with a willingness to pay higher than the market price will buy the good
|
154
|
+
demand_table_in_market = demand_table.where(0, are.above_or_equal_to(price))
|
155
|
+
|
156
|
+
cs = (demand_table_in_market.column(0) - price) * demand_table_in_market.column(1)
|
157
|
+
total_cs = sum(cs)
|
158
|
+
|
159
|
+
return total_cs
|
160
|
+
```
|
161
|
+
|
162
|
+
```python
|
163
|
+
cs_burrito = consumer_surplus(DemandBurr, 10)
|
164
|
+
print('The consumer surplus from counting consumers is', cs_burrito)
|
165
|
+
```
|
166
|
+
|
167
|
+
How can we visualize the consumer surplus on the demand and supply diagram? We'll start by creating a demand curve first like before.
|
168
|
+
|
169
|
+
```python
|
170
|
+
DemandBurr.scatter("Qdemand", "priceBurr")
|
171
|
+
plt.xlabel('Quantity')
|
172
|
+
plt.ylabel('Price')
|
173
|
+
plt.title('Demand for Gourmet Burrito');
|
174
|
+
```
|
175
|
+
|
176
|
+
```python
|
177
|
+
DemandBurr.plot("Qdemand", "priceBurr", linewidth= 3)
|
178
|
+
plt.xlabel('Quantity')
|
179
|
+
plt.ylabel('Price')
|
180
|
+
plt.title('Demand for Gourmet Burrito');
|
181
|
+
```
|
182
|
+
|
183
|
+
Now that we have a demand curve - Let's create for a model that makes a linear approximation like we did in lecture 2.
|
184
|
+
|
185
|
+
```python
|
186
|
+
DemandGM = np.polyfit(DemandBurr.column("Qdemand"), DemandBurr.column("priceBurr"),1)
|
187
|
+
DemandGM
|
188
|
+
```
|
189
|
+
|
190
|
+
```python
|
191
|
+
burr_slope = DemandGM.item(0)
|
192
|
+
burr_slope
|
193
|
+
```
|
194
|
+
|
195
|
+
```python
|
196
|
+
burr_intercept = DemandGM.item(1)
|
197
|
+
burr_intercept
|
198
|
+
```
|
199
|
+
|
200
|
+
```python
|
201
|
+
# plot the actual demand curve
|
202
|
+
DemandBurr.plot("Qdemand", "priceBurr", linewidth=3)
|
203
|
+
|
204
|
+
# plot the linear approximation
|
205
|
+
burr_quantities = np.arange(0,120,0.01)
|
206
|
+
burr_prices = burr_slope * burr_quantities + burr_intercept
|
207
|
+
plt.plot(burr_quantities, burr_prices, linewidth=3)
|
208
|
+
|
209
|
+
plt.xlabel('Quantity')
|
210
|
+
plt.ylabel('Price')
|
211
|
+
plt.title('Demand for Burrito');
|
212
|
+
```
|
213
|
+
|
214
|
+
How many people does the model think would buy burritos when its price is \\$10? Let's answer this question using sympy.
|
215
|
+
|
216
|
+
```python
|
217
|
+
# Set up the demand curve expression
|
218
|
+
Q = sympy.Symbol("Q")
|
219
|
+
demand = burr_slope * Q + burr_intercept
|
220
|
+
|
221
|
+
# Solve for Q_star when price is 10
|
222
|
+
Q_Star = solve(demand, 10)
|
223
|
+
Q_Star
|
224
|
+
```
|
225
|
+
|
226
|
+
Now we will visualize the consumer surplus of the burrito market.
|
227
|
+
|
228
|
+
```python
|
229
|
+
DemandBurr.plot("Qdemand", "priceBurr", linewidth= 3) #Black : Demand for buritto
|
230
|
+
|
231
|
+
plt.plot(np.arange(0,82,0.01), burr_slope * np.arange(0,82,0.01) + burr_intercept, linewidth= 3) #Blue :
|
232
|
+
|
233
|
+
price = 10
|
234
|
+
plt.plot([0,Q_Star],[price, price], color = 'r', linewidth= 3) #Red : Price
|
235
|
+
|
236
|
+
triangle1 = patches.Polygon([[0,10],[Q_Star,10],[0,burr_intercept]],True,color="green") #Consumer surplus
|
237
|
+
currentAxis = plt.gca()
|
238
|
+
currentAxis.add_patch(triangle1)
|
239
|
+
|
240
|
+
plt.xlabel('Quantity')
|
241
|
+
plt.ylabel('Price')
|
242
|
+
plt.title('Demand for Burrito')
|
243
|
+
|
244
|
+
burr_price = 10
|
245
|
+
|
246
|
+
# Code for Slope and Intercept - What are the slope and intercept of the fit line
|
247
|
+
std_units = lambda a: (a - np.mean(a)) / np.std(a)
|
248
|
+
corr = lambda x, y: np.mean(std_units(x) * std_units(y))
|
249
|
+
slope = lambda x, y: corr(x, y) * np.std(y) / np.std(x)
|
250
|
+
intercept = lambda x, y: np.mean(y) - slope(x, y) * np.mean(x)
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
# Sums up the surplus at the give price
|
255
|
+
def surplus(bins, data, price):
|
256
|
+
#Finding the quatity at the point where red line indicating surplus and blue line indicating the relationship btw quantiy and price.
|
257
|
+
slope_sur = slope(data, bins)
|
258
|
+
intercept_sur = intercept(data, bins)
|
259
|
+
Q = sympy.Symbol("Q")
|
260
|
+
demand = slope_sur * Q + intercept_sur
|
261
|
+
Q_Star = solve(demand, price)
|
262
|
+
|
263
|
+
#Sums up the surplus and print it out.
|
264
|
+
total_surplus = .5 * Q_Star * (intercept_sur - price)
|
265
|
+
return total_surplus
|
266
|
+
|
267
|
+
agg_surplus = surplus(DemandBurr["priceBurr"], DemandBurr["Qdemand"], burr_price)
|
268
|
+
print("Consumer surplus is equal to green triangle: " + str(0.5 * (burr_intercept - burr_price) * Q_Star))
|
269
|
+
```
|
270
|
+
|
271
|
+
### Let's try again for Greek Theater Tickets
|
272
|
+
|
273
|
+
```python
|
274
|
+
GreekTixTable = DemandTable.select('GreekTix')
|
275
|
+
GreekTixTable
|
276
|
+
```
|
277
|
+
|
278
|
+
```python
|
279
|
+
# apply the same trick to obtain demand at each price
|
280
|
+
Qdemand = np.flip(np.cumsum(np.flip(GreekTixTable.group("GreekTix").column("count"))))
|
281
|
+
```
|
282
|
+
|
283
|
+
```python
|
284
|
+
DemandGreekTix = Table().with_columns([
|
285
|
+
'priceTix', [25, 50, 75, 100, 125, 150, 175, 200],
|
286
|
+
'Qdemand', Qdemand
|
287
|
+
])
|
288
|
+
DemandGreekTix
|
289
|
+
```
|
290
|
+
|
291
|
+
```python
|
292
|
+
tix_slope = slope(DemandGreekTix["Qdemand"], DemandGreekTix["priceTix"])
|
293
|
+
tix_intercept = intercept(DemandGreekTix["Qdemand"], DemandGreekTix["priceTix"])
|
294
|
+
tix_slope, tix_intercept
|
295
|
+
```
|
296
|
+
|
297
|
+
How many people does the Model think would buy at \\$100? Let's again use sympy.
|
298
|
+
|
299
|
+
```python
|
300
|
+
solve = lambda x,y: sympy.solve(x-y)[0] if len(sympy.solve(x-y))==1 else "Not Single Solution"
|
301
|
+
Q = sympy.Symbol("Q")
|
302
|
+
demand = tix_slope * Q + tix_intercept
|
303
|
+
|
304
|
+
Q_Star = solve(demand, 100)
|
305
|
+
Q_Star
|
306
|
+
```
|
307
|
+
|
308
|
+
Visualize the consumer surplus for Greek Theater tickets!
|
309
|
+
|
310
|
+
```python
|
311
|
+
DemandGreekTix.plot("Qdemand", "priceTix", linewidth=3, zorder=20) #Black : Demand for Greek Theater
|
312
|
+
|
313
|
+
triangle1 = patches.Polygon([[0,100],[Q_Star,100],[0,tix_intercept]], True, color="green", zorder=1)
|
314
|
+
currentAxis = plt.gca()
|
315
|
+
currentAxis.add_patch(triangle1)
|
316
|
+
|
317
|
+
plt.plot(np.arange(0,82,0.01), tix_slope * np.arange(0,82,0.01) + tix_intercept, linewidth= 3, zorder=5) #Blue : Demand
|
318
|
+
|
319
|
+
price = 100
|
320
|
+
|
321
|
+
# This line to interactive version
|
322
|
+
plt.plot([0,Q_Star],[price]*2, color = 'r', linewidth= 3, zorder = 10) #Red : Price
|
323
|
+
|
324
|
+
plt.xlabel('Quantity')
|
325
|
+
plt.ylabel('Price')
|
326
|
+
plt.title('Demand for Greek Theater Tickets');
|
327
|
+
|
328
|
+
agg_surplus = surplus(DemandGreekTix["priceTix"], DemandGreekTix["Qdemand"], price)
|
329
|
+
print("Consumer surplus is equal to green triangle: " + str(agg_surplus))
|
330
|
+
```
|
331
|
+
|