Skip to content

Commit 07b67e8

Browse files
committed
update plot legends
1 parent f30656b commit 07b67e8

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Loading

lectures/long_run_growth.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ kernelspec:
1111
name: python3
1212
---
1313

14+
+++ {"user_expressions": []}
15+
1416
# Economic Growth Evidence
1517

1618
## Overview
@@ -75,6 +77,8 @@ from collections import namedtuple
7577
from matplotlib.lines import Line2D
7678
```
7779

80+
+++ {"user_expressions": []}
81+
7882
## Setting up
7983

8084
A project initiated by [Angus Maddison](https://en.wikipedia.org/wiki/Angus_Maddison) has collected many historical time series related to economic growth,
@@ -91,6 +95,8 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Full data')
9195
data
9296
```
9397

98+
+++ {"user_expressions": []}
99+
94100
We can see that this dataset contains GDP per capita (gdppc) and population (pop) for many countries and years.
95101

96102
Let's look at how many and which countries are available in this dataset
@@ -99,6 +105,8 @@ Let's look at how many and which countries are available in this dataset
99105
len(data.country.unique())
100106
```
101107

108+
+++ {"user_expressions": []}
109+
102110
We can now explore some of the 169 countries that are available.
103111

104112
Let's loop over each country to understand which years are available for each country
@@ -113,6 +121,8 @@ cntry_years = pd.DataFrame(cntry_years, columns=['country', 'Min Year', 'Max Yea
113121
cntry_years
114122
```
115123

124+
+++ {"user_expressions": []}
125+
116126
Let's now reshape the original data into some convenient variables to enable quicker access to countries time series data.
117127

118128
We can build a useful mapping between country codes and country names in this dataset
@@ -121,6 +131,8 @@ We can build a useful mapping between country codes and country names in this da
121131
code_to_name = data[['countrycode','country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
122132
```
123133

134+
+++ {"user_expressions": []}
135+
124136
Then we can quickly focus on GDP per capita (gdp)
125137

126138
```{code-cell} ipython3
@@ -136,6 +148,8 @@ gdppc = gdppc.unstack('countrycode')
136148
gdppc
137149
```
138150

151+
+++ {"user_expressions": []}
152+
139153
We create a color mapping between country codes and colors for consistency
140154

141155
```{code-cell} ipython3
@@ -150,6 +164,8 @@ colors = cm.tab20(np.linspace(0, 0.95, len(country_names)))
150164
color_mapping = {country: color for country, color in zip(country_names, colors)}
151165
```
152166

167+
+++ {"user_expressions": []}
168+
153169
## GPD plots
154170

155171
Looking at the United Kingdom we can first confirm we are using the correct country code
@@ -172,6 +188,8 @@ _ = gdppc[cntry].plot(
172188
color=color_mapping['GBR'])
173189
```
174190

191+
+++ {"user_expressions": []}
192+
175193
:::{note}
176194
[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).
177195
:::
@@ -203,6 +221,8 @@ ax.set_xlabel('Year')
203221
plt.show()
204222
```
205223

224+
+++ {"user_expressions": []}
225+
206226
We can now put this into a function to generate plots for a list of countries
207227

208228
```{code-cell} ipython3
@@ -232,13 +252,15 @@ def draw_interp_plots(series, ylabel, xlabel, color_mapping, code_to_name, lw, l
232252
ax.set_yscale('log')
233253
234254
# Draw the legend outside the plot
235-
ax.legend(loc='lower center', ncol=6, bbox_to_anchor=[0.5, -0.25])
255+
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon=False)
236256
ax.set_ylabel(ylabel)
237257
ax.set_xlabel(xlabel)
238258
239259
return ax
240260
```
241261

262+
+++ {"user_expressions": []}
263+
242264
As you can see from this chart, economic growth started in earnest in the 18th century and continued for the next two hundred years.
243265

244266
How does this compare with other countries' growth trajectories?
@@ -311,6 +333,8 @@ draw_events(events, ax)
311333
plt.show()
312334
```
313335

336+
+++ {"user_expressions": []}
337+
314338
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
315339
groups of people
316340

@@ -380,6 +404,8 @@ draw_events(events, ax)
380404
plt.show()
381405
```
382406

407+
+++ {"user_expressions": []}
408+
383409
We can also look at the United States (USA) and United Kingdom (GBR) in more detail
384410

385411
In the following graph, please watch for
@@ -439,6 +465,8 @@ draw_events(events, ax)
439465
plt.show()
440466
```
441467

468+
+++ {"user_expressions": []}
469+
442470
## The industrialized world
443471

444472
Now we'll construct some graphs of interest to geopolitical historians like Adam Tooze.
@@ -452,6 +480,8 @@ data['gdp'] = data['gdppc'] * data['pop']
452480
gdp = data['gdp'].unstack('countrycode')
453481
```
454482

483+
+++ {"user_expressions": []}
484+
455485
### Early industrialization (1820 to 1940)
456486

457487
We first visualize the trend of China, the Former Soviet Union, Japan, the UK and the US.
@@ -478,6 +508,8 @@ ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
478508
color_mapping, code_to_name, 2, False, ax)
479509
```
480510

511+
+++ {"user_expressions": []}
512+
481513
## Constructing a plot similar to Tooze's
482514
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.
483515

@@ -488,6 +520,8 @@ BEM = ['GBR', 'IND', 'AUS', 'NZL', 'CAN', 'ZAF']
488520
gdp['BEM'] = gdp[BEM].loc[start_year-1:end_year].interpolate(method='index').sum(axis=1) # Interpolate incomplete time-series
489521
```
490522

523+
+++ {"user_expressions": []}
524+
491525
Let's take a look at the aggregation that represents the British Empire.
492526

493527
```{code-cell} ipython3
@@ -498,6 +532,8 @@ gdp['BEM'].plot() # The first year is np.nan due to interpolation
498532
code_to_name
499533
```
500534

535+
+++ {"user_expressions": []}
536+
501537
Now let's assemble our series and get ready to plot them.
502538

503539
```{code-cell} ipython3
@@ -521,6 +557,8 @@ plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dp
521557
plt.show()
522558
```
523559

560+
+++ {"user_expressions": []}
561+
524562
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
525563
by the end of the 19th century, setting the geopolitical stage for the "American (twentieth) century".
526564

@@ -548,6 +586,8 @@ ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
548586
color_mapping, code_to_name, 2, False, ax)
549587
```
550588

589+
+++ {"user_expressions": []}
590+
551591
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`.
552592

553593
## Regional analysis
@@ -561,19 +601,25 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header
561601
data.columns = data.columns.droplevel(level=2)
562602
```
563603

604+
+++ {"user_expressions": []}
605+
564606
We can save the raw data in a more convenient format to build a single table of regional GDP per capita
565607

566608
```{code-cell} ipython3
567609
regionalgdppc = data['gdppc_2011'].copy()
568610
regionalgdppc.index = pd.to_datetime(regionalgdppc.index, format='%Y')
569611
```
570612

613+
+++ {"user_expressions": []}
614+
571615
Let's interpolate based on time to fill in any gaps in the dataset for the purpose of plotting
572616

573617
```{code-cell} ipython3
574618
regionalgdppc.interpolate(method='time', inplace=True)
575619
```
576620

621+
+++ {"user_expressions": []}
622+
577623
and record a dataset of world GDP per capita
578624

579625
```{code-cell} ipython3
@@ -596,6 +642,8 @@ ax = worldgdppc.plot(
596642
)
597643
```
598644

645+
+++ {"user_expressions": []}
646+
599647
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.
600648

601649
Again we see the divergence of the West from the rest of the world after the industrial revolution and the convergence of the world after the 1950s

0 commit comments

Comments
 (0)