Skip to content

Commit 8923f9e

Browse files
authored
long_run_growth: styling and label fixes (#328)
* styling and label fixes * fix
1 parent 55bdc28 commit 8923f9e

File tree

1 file changed

+41
-59
lines changed

1 file changed

+41
-59
lines changed

lectures/long_run_growth.md

Lines changed: 41 additions & 59 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

@@ -68,16 +67,12 @@ First let's import the packages needed to explore what the data says about long
6867

6968
```{code-cell} ipython3
7069
import pandas as pd
71-
import os
72-
import matplotlib as mpl
7370
import matplotlib.pyplot as plt
7471
import matplotlib.cm as cm
7572
import numpy as np
7673
from collections import namedtuple
77-
from matplotlib.lines import Line2D
7874
```
7975

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

8277
## Setting up
8378

@@ -95,7 +90,6 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Full data')
9590
data
9691
```
9792

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

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

@@ -105,7 +99,6 @@ Let's look at how many and which countries are available in this dataset
10599
len(data.country.unique())
106100
```
107101

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

110103
We can now explore some of the 169 countries that are available.
111104

@@ -117,21 +110,20 @@ for cntry in data.country.unique():
117110
cy_data = data[data.country == cntry]['year']
118111
ymin, ymax = cy_data.min(), cy_data.max()
119112
cntry_years.append((cntry, ymin, ymax))
120-
cntry_years = pd.DataFrame(cntry_years, columns=['country', 'Min Year', 'Max Year']).set_index('country')
113+
cntry_years = pd.DataFrame(cntry_years,
114+
columns=['country', 'Min Year', 'Max Year']).set_index('country')
121115
cntry_years
122116
```
123117

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

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

128121
We can build a useful mapping between country codes and country names in this dataset
129122

130123
```{code-cell} ipython3
131-
code_to_name = data[['countrycode','country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
124+
code_to_name = data[['countrycode', 'country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
132125
```
133126

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

136128
Then we can quickly focus on GDP per capita (gdp)
137129

@@ -140,15 +132,14 @@ data
140132
```
141133

142134
```{code-cell} ipython3
143-
gdppc = data.set_index(['countrycode','year'])['gdppc']
135+
gdppc = data.set_index(['countrycode', 'year'])['gdppc']
144136
gdppc = gdppc.unstack('countrycode')
145137
```
146138

147139
```{code-cell} ipython3
148140
gdppc
149141
```
150142

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

153144
We create a color mapping between country codes and colors for consistency
154145

@@ -179,14 +170,14 @@ mystnb:
179170
fig, ax = plt.subplots(dpi=300)
180171
cntry = 'GBR'
181172
_ = gdppc[cntry].plot(
182-
ax = fig.gca(),
183-
ylabel = 'International $\'s',
184-
xlabel = 'Year',
185-
linestyle='-',
186-
color=color_mapping['GBR'])
173+
ax=fig.gca(),
174+
ylabel='International $\'s',
175+
xlabel='Year',
176+
linestyle='-',
177+
color=color_mapping['GBR']
178+
)
187179
```
188180

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

191182
:::{note}
192183
[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 +210,6 @@ ax.set_xlabel('Year')
219210
plt.show()
220211
```
221212

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

224214
We can now put this into a function to generate plots for a list of countries
225215

@@ -257,7 +247,6 @@ def draw_interp_plots(series, ylabel, xlabel, color_mapping, code_to_name, lw, l
257247
return ax
258248
```
259249

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

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

@@ -280,8 +269,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
280269
281270
cntry = ['CHN', 'GBR', 'USA']
282271
ax = draw_interp_plots(gdppc[cntry].loc[1500:],
283-
'International $\'s','Year',
284-
color_mapping, code_to_name, 2, False, ax)
272+
'International $\'s','Year',
273+
color_mapping, code_to_name, 2, False, ax)
285274
286275
# Define the parameters for the events and the text
287276
ylim = ax.get_ylim()[1]
@@ -322,16 +311,14 @@ def draw_events(events, ax):
322311
event.y_text, event.text,
323312
color=event.color, **t_params)
324313
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-
314+
ax.axvline(event_mid, ymin=1, ymax=event.ymax, color=event.color,
315+
linestyle='-', clip_on=False, alpha=0.15)
316+
329317
# Draw events
330318
draw_events(events, ax)
331319
plt.show()
332320
```
333321

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

336323
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
337324
groups of people
@@ -365,8 +352,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
365352
366353
cntry = ['CHN']
367354
ax = draw_interp_plots(gdppc[cntry].loc[1600:2000],
368-
'International $\'s','Year',
369-
color_mapping, code_to_name, 2, True, ax)
355+
'International $\'s','Year',
356+
color_mapping, code_to_name, 2, True, ax)
370357
371358
ylim = ax.get_ylim()[1]
372359
@@ -402,7 +389,6 @@ draw_events(events, ax)
402389
plt.show()
403390
```
404391

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

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

@@ -425,8 +411,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
425411
426412
cntry = ['GBR', 'USA']
427413
ax = draw_interp_plots(gdppc[cntry].loc[1500:2000],
428-
'International $\'s','Year',
429-
color_mapping, code_to_name, 2, True, ax)
414+
'International $\'s','Year',
415+
color_mapping, code_to_name, 2, True, ax)
430416
431417
ylim = ax.get_ylim()[1]
432418
@@ -463,7 +449,6 @@ draw_events(events, ax)
463449
plt.show()
464450
```
465451

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

468453
## The industrialized world
469454

@@ -478,7 +463,6 @@ data['gdp'] = data['gdppc'] * data['pop']
478463
gdp = data['gdp'].unstack('countrycode')
479464
```
480465

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

483467
### Early industrialization (1820 to 1940)
484468

@@ -502,11 +486,10 @@ ax = fig.gca()
502486
cntry = ['CHN', 'SUN', 'JPN', 'GBR', 'USA']
503487
start_year, end_year = (1820, 1945)
504488
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
505-
'International $\'s','Year',
506-
color_mapping, code_to_name, 2, False, ax)
489+
'International $\'s', 'Year',
490+
color_mapping, code_to_name, 2, False, ax)
507491
```
508492

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

511494
## Constructing a plot similar to Tooze's
512495
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.
@@ -515,22 +498,23 @@ Let's first define a collection of countries that consist of the British Empire
515498

516499
```{code-cell} ipython3
517500
BEM = ['GBR', 'IND', 'AUS', 'NZL', 'CAN', 'ZAF']
518-
gdp['BEM'] = gdp[BEM].loc[start_year-1:end_year].interpolate(method='index').sum(axis=1) # Interpolate incomplete time-series
501+
# Interpolate incomplete time-series
502+
gdp['BEM'] = gdp[BEM].loc[start_year-1:end_year].interpolate(method='index').sum(axis=1)
519503
```
520504

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

523506
Let's take a look at the aggregation that represents the British Empire.
524507

525508
```{code-cell} ipython3
526-
gdp['BEM'].plot() # The first year is np.nan due to interpolation
509+
# The first year is np.nan due to interpolation
510+
gdp['BEM'].plot(ylabel="International $'s")
511+
plt.show()
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)