Skip to content

Commit 37222a8

Browse files
committed
styling and label fixes
1 parent f46622b commit 37222a8

File tree

1 file changed

+37
-55
lines changed

1 file changed

+37
-55
lines changed

lectures/long_run_growth.md

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.5
7+
jupytext_version: 1.15.2
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
1111
name: python3
1212
---
1313

14-
+++ {"user_expressions": []}
1514

1615
# Economic Growth Evidence
1716

@@ -77,7 +76,6 @@ from collections import namedtuple
7776
from matplotlib.lines import Line2D
7877
```
7978

80-
+++ {"user_expressions": []}
8179

8280
## Setting up
8381

@@ -95,7 +93,6 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Full data')
9593
data
9694
```
9795

98-
+++ {"user_expressions": []}
9996

10097
We can see that this dataset contains GDP per capita (gdppc) and population (pop) for many countries and years.
10198

@@ -105,7 +102,6 @@ Let's look at how many and which countries are available in this dataset
105102
len(data.country.unique())
106103
```
107104

108-
+++ {"user_expressions": []}
109105

110106
We can now explore some of the 169 countries that are available.
111107

@@ -117,21 +113,20 @@ for cntry in data.country.unique():
117113
cy_data = data[data.country == cntry]['year']
118114
ymin, ymax = cy_data.min(), cy_data.max()
119115
cntry_years.append((cntry, ymin, ymax))
120-
cntry_years = pd.DataFrame(cntry_years, columns=['country', 'Min Year', 'Max Year']).set_index('country')
116+
cntry_years = pd.DataFrame(cntry_years,
117+
columns=['country', 'Min Year', 'Max Year']).set_index('country')
121118
cntry_years
122119
```
123120

124-
+++ {"user_expressions": []}
125121

126122
Let's now reshape the original data into some convenient variables to enable quicker access to countries time series data.
127123

128124
We can build a useful mapping between country codes and country names in this dataset
129125

130126
```{code-cell} ipython3
131-
code_to_name = data[['countrycode','country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
127+
code_to_name = data[['countrycode', 'country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
132128
```
133129

134-
+++ {"user_expressions": []}
135130

136131
Then we can quickly focus on GDP per capita (gdp)
137132

@@ -140,15 +135,14 @@ data
140135
```
141136

142137
```{code-cell} ipython3
143-
gdppc = data.set_index(['countrycode','year'])['gdppc']
138+
gdppc = data.set_index(['countrycode', 'year'])['gdppc']
144139
gdppc = gdppc.unstack('countrycode')
145140
```
146141

147142
```{code-cell} ipython3
148143
gdppc
149144
```
150145

151-
+++ {"user_expressions": []}
152146

153147
We create a color mapping between country codes and colors for consistency
154148

@@ -179,14 +173,14 @@ mystnb:
179173
fig, ax = plt.subplots(dpi=300)
180174
cntry = 'GBR'
181175
_ = gdppc[cntry].plot(
182-
ax = fig.gca(),
183-
ylabel = 'International $\'s',
184-
xlabel = 'Year',
185-
linestyle='-',
186-
color=color_mapping['GBR'])
176+
ax=fig.gca(),
177+
ylabel='International $\'s',
178+
xlabel='Year',
179+
linestyle='-',
180+
color=color_mapping['GBR']
181+
)
187182
```
188183

189-
+++ {"user_expressions": []}
190184

191185
:::{note}
192186
[International Dollars](https://en.wikipedia.org/wiki/International_dollar) are a hypothetical unit of currency that has the same purchasing power parity that the U.S. Dollar has in the United States at any given time. They are also known as Geary–Khamis dollars (GK Dollars).
@@ -219,7 +213,6 @@ ax.set_xlabel('Year')
219213
plt.show()
220214
```
221215

222-
+++ {"user_expressions": []}
223216

224217
We can now put this into a function to generate plots for a list of countries
225218

@@ -257,7 +250,6 @@ def draw_interp_plots(series, ylabel, xlabel, color_mapping, code_to_name, lw, l
257250
return ax
258251
```
259252

260-
+++ {"user_expressions": []}
261253

262254
As you can see from this chart, economic growth started in earnest in the 18th century and continued for the next two hundred years.
263255

@@ -280,8 +272,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
280272
281273
cntry = ['CHN', 'GBR', 'USA']
282274
ax = draw_interp_plots(gdppc[cntry].loc[1500:],
283-
'International $\'s','Year',
284-
color_mapping, code_to_name, 2, False, ax)
275+
'International $\'s','Year',
276+
color_mapping, code_to_name, 2, False, ax)
285277
286278
# Define the parameters for the events and the text
287279
ylim = ax.get_ylim()[1]
@@ -322,16 +314,14 @@ def draw_events(events, ax):
322314
event.y_text, event.text,
323315
color=event.color, **t_params)
324316
ax.axvspan(*event.year_range, color=event.color, alpha=0.2)
325-
ax.axvline(event_mid, ymin=1,
326-
ymax=event.ymax, color=event.color,
327-
linestyle='-', clip_on=False, alpha=0.15)
328-
317+
ax.axvline(event_mid, ymin=1, ymax=event.ymax, color=event.color,
318+
linestyle='-', clip_on=False, alpha=0.15)
319+
329320
# Draw events
330321
draw_events(events, ax)
331322
plt.show()
332323
```
333324

334-
+++ {"user_expressions": []}
335325

336326
The preceding graph of per capita GDP strikingly reveals how the spread of the industrial revolution has over time gradually lifted the living standards of substantial
337327
groups of people
@@ -365,8 +355,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
365355
366356
cntry = ['CHN']
367357
ax = draw_interp_plots(gdppc[cntry].loc[1600:2000],
368-
'International $\'s','Year',
369-
color_mapping, code_to_name, 2, True, ax)
358+
'International $\'s','Year',
359+
color_mapping, code_to_name, 2, True, ax)
370360
371361
ylim = ax.get_ylim()[1]
372362
@@ -402,7 +392,6 @@ draw_events(events, ax)
402392
plt.show()
403393
```
404394

405-
+++ {"user_expressions": []}
406395

407396
We can also look at the United States (USA) and United Kingdom (GBR) in more detail
408397

@@ -425,8 +414,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
425414
426415
cntry = ['GBR', 'USA']
427416
ax = draw_interp_plots(gdppc[cntry].loc[1500:2000],
428-
'International $\'s','Year',
429-
color_mapping, code_to_name, 2, True, ax)
417+
'International $\'s','Year',
418+
color_mapping, code_to_name, 2, True, ax)
430419
431420
ylim = ax.get_ylim()[1]
432421
@@ -463,7 +452,6 @@ draw_events(events, ax)
463452
plt.show()
464453
```
465454

466-
+++ {"user_expressions": []}
467455

468456
## The industrialized world
469457

@@ -478,7 +466,6 @@ data['gdp'] = data['gdppc'] * data['pop']
478466
gdp = data['gdp'].unstack('countrycode')
479467
```
480468

481-
+++ {"user_expressions": []}
482469

483470
### Early industrialization (1820 to 1940)
484471

@@ -502,11 +489,10 @@ ax = fig.gca()
502489
cntry = ['CHN', 'SUN', 'JPN', 'GBR', 'USA']
503490
start_year, end_year = (1820, 1945)
504491
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
505-
'International $\'s','Year',
506-
color_mapping, code_to_name, 2, False, ax)
492+
'International $\'s', 'Year',
493+
color_mapping, code_to_name, 2, False, ax)
507494
```
508495

509-
+++ {"user_expressions": []}
510496

511497
## Constructing a plot similar to Tooze's
512498
In this section we describe how we have constructed a version of the striking figure from chapter 1 of {cite}`Tooze_2014` that we discussed at the start of this lecture.
@@ -518,19 +504,17 @@ BEM = ['GBR', 'IND', 'AUS', 'NZL', 'CAN', 'ZAF']
518504
gdp['BEM'] = gdp[BEM].loc[start_year-1:end_year].interpolate(method='index').sum(axis=1) # Interpolate incomplete time-series
519505
```
520506

521-
+++ {"user_expressions": []}
522507

523508
Let's take a look at the aggregation that represents the British Empire.
524509

525510
```{code-cell} ipython3
526-
gdp['BEM'].plot() # The first year is np.nan due to interpolation
511+
gdp['BEM'].plot(ylabel="International $'s") # The first year is np.nan due to interpolation
527512
```
528513

529514
```{code-cell} ipython3
530515
code_to_name
531516
```
532517

533-
+++ {"user_expressions": []}
534518

535519
Now let's assemble our series and get ready to plot them.
536520

@@ -549,13 +533,14 @@ ax = fig.gca()
549533
cntry = ['DEU', 'USA', 'SUN', 'BEM', 'FRA', 'JPN']
550534
start_year, end_year = (1821, 1945)
551535
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
552-
'Real GDP in 2011 $\'s','Year',
553-
color_mapping, code_to_name, 2, False, ax)
554-
plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dpi=300, bbox_inches='tight')
536+
'Real GDP in 2011 $\'s', 'Year',
537+
color_mapping, code_to_name, 2, False, ax)
538+
539+
plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dpi=300,
540+
bbox_inches='tight')
555541
plt.show()
556542
```
557543

558-
+++ {"user_expressions": []}
559544

560545
At the start of this lecture, we noted how US GDP came from "nowhere" at the start of the 19th century to rival and then overtake the GDP of the British Empire
561546
by the end of the 19th century, setting the geopolitical stage for the "American (twentieth) century".
@@ -580,11 +565,10 @@ ax = fig.gca()
580565
cntry = ['CHN', 'SUN', 'JPN', 'GBR', 'USA']
581566
start_year, end_year = (1950, 2020)
582567
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
583-
'International $\'s','Year',
584-
color_mapping, code_to_name, 2, False, ax)
568+
'International $\'s', 'Year',
569+
color_mapping, code_to_name, 2, False, ax)
585570
```
586571

587-
+++ {"user_expressions": []}
588572

589573
It is tempting to compare this graph with figure {numref}`gdp1` that showed the US overtaking the UK near the start of the "American Century", a version of the graph featured in chapter 1 of {cite}`Tooze_2014`.
590574

@@ -595,11 +579,11 @@ We often want to study historical experiences of countries outside the club of "
595579
Fortunately, the [Maddison Historical Statistics](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) dataset also includes regional aggregations
596580

597581
```{code-cell} ipython3
598-
data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header=(0,1,2), index_col=0)
582+
data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header=(0,1,2),
583+
index_col=0)
599584
data.columns = data.columns.droplevel(level=2)
600585
```
601586

602-
+++ {"user_expressions": []}
603587

604588
We can save the raw data in a more convenient format to build a single table of regional GDP per capita
605589

@@ -608,15 +592,13 @@ regionalgdppc = data['gdppc_2011'].copy()
608592
regionalgdppc.index = pd.to_datetime(regionalgdppc.index, format='%Y')
609593
```
610594

611-
+++ {"user_expressions": []}
612595

613596
Let's interpolate based on time to fill in any gaps in the dataset for the purpose of plotting
614597

615598
```{code-cell} ipython3
616599
regionalgdppc.interpolate(method='time', inplace=True)
617600
```
618601

619-
+++ {"user_expressions": []}
620602

621603
and record a dataset of world GDP per capita
622604

@@ -634,13 +616,12 @@ mystnb:
634616
fig = plt.figure(dpi=300)
635617
ax = fig.gca()
636618
ax = worldgdppc.plot(
637-
ax = ax,
619+
ax=ax,
638620
xlabel='Year',
639621
ylabel='2011 US$',
640622
)
641623
```
642624

643-
+++ {"user_expressions": []}
644625

645626
Looking more closely, let's compare the time series for `Western Offshoots` and `Sub-Saharan Africa` and more broadly at a number of different regions around the world.
646627

@@ -656,9 +637,10 @@ mystnb:
656637
fig = plt.figure(dpi=300)
657638
ax = fig.gca()
658639
line_styles = ['-', '--', ':', '-.', '.', 'o', '-', '--', '-']
659-
ax = regionalgdppc.plot(ax = ax, style=line_styles)
640+
ax = regionalgdppc.plot(ax=ax, xlabel='Year',
641+
ylabel='2011 US$', style=line_styles)
660642
ax.set_yscale('log')
661-
plt.legend(loc='lower center',
662-
ncol=3, bbox_to_anchor=[0.5, -0.4])
643+
plt.legend(loc='lower center',
644+
ncol=3, bbox_to_anchor=[0.5, -0.4])
663645
plt.show()
664646
```

0 commit comments

Comments
 (0)