-
-
Notifications
You must be signed in to change notification settings - Fork 26
long_run_growth: styling and label fixes #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,14 +4,13 @@ jupytext: | |||||||||||
extension: .md | ||||||||||||
format_name: myst | ||||||||||||
format_version: 0.13 | ||||||||||||
jupytext_version: 1.14.5 | ||||||||||||
jupytext_version: 1.15.2 | ||||||||||||
kernelspec: | ||||||||||||
display_name: Python 3 (ipykernel) | ||||||||||||
language: python | ||||||||||||
name: python3 | ||||||||||||
--- | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
# Economic Growth Evidence | ||||||||||||
|
||||||||||||
|
@@ -77,7 +76,6 @@ from collections import namedtuple | |||||||||||
from matplotlib.lines import Line2D | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
## Setting up | ||||||||||||
|
||||||||||||
|
@@ -95,7 +93,6 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Full data') | |||||||||||
data | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
We can see that this dataset contains GDP per capita (gdppc) and population (pop) for many countries and years. | ||||||||||||
|
||||||||||||
|
@@ -105,7 +102,6 @@ Let's look at how many and which countries are available in this dataset | |||||||||||
len(data.country.unique()) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
We can now explore some of the 169 countries that are available. | ||||||||||||
|
||||||||||||
|
@@ -117,21 +113,20 @@ for cntry in data.country.unique(): | |||||||||||
cy_data = data[data.country == cntry]['year'] | ||||||||||||
ymin, ymax = cy_data.min(), cy_data.max() | ||||||||||||
cntry_years.append((cntry, ymin, ymax)) | ||||||||||||
cntry_years = pd.DataFrame(cntry_years, columns=['country', 'Min Year', 'Max Year']).set_index('country') | ||||||||||||
cntry_years = pd.DataFrame(cntry_years, | ||||||||||||
columns=['country', 'Min Year', 'Max Year']).set_index('country') | ||||||||||||
cntry_years | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
Let's now reshape the original data into some convenient variables to enable quicker access to countries time series data. | ||||||||||||
|
||||||||||||
We can build a useful mapping between country codes and country names in this dataset | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
code_to_name = data[['countrycode','country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode']) | ||||||||||||
code_to_name = data[['countrycode', 'country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode']) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
Then we can quickly focus on GDP per capita (gdp) | ||||||||||||
|
||||||||||||
|
@@ -140,15 +135,14 @@ data | |||||||||||
``` | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
gdppc = data.set_index(['countrycode','year'])['gdppc'] | ||||||||||||
gdppc = data.set_index(['countrycode', 'year'])['gdppc'] | ||||||||||||
gdppc = gdppc.unstack('countrycode') | ||||||||||||
``` | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
gdppc | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
We create a color mapping between country codes and colors for consistency | ||||||||||||
|
||||||||||||
|
@@ -179,14 +173,14 @@ mystnb: | |||||||||||
fig, ax = plt.subplots(dpi=300) | ||||||||||||
cntry = 'GBR' | ||||||||||||
_ = gdppc[cntry].plot( | ||||||||||||
ax = fig.gca(), | ||||||||||||
ylabel = 'International $\'s', | ||||||||||||
xlabel = 'Year', | ||||||||||||
linestyle='-', | ||||||||||||
color=color_mapping['GBR']) | ||||||||||||
ax=fig.gca(), | ||||||||||||
ylabel='International $\'s', | ||||||||||||
xlabel='Year', | ||||||||||||
linestyle='-', | ||||||||||||
color=color_mapping['GBR'] | ||||||||||||
) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
:::{note} | ||||||||||||
[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') | |||||||||||
plt.show() | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
We can now put this into a function to generate plots for a list of countries | ||||||||||||
|
||||||||||||
|
@@ -257,7 +250,6 @@ def draw_interp_plots(series, ylabel, xlabel, color_mapping, code_to_name, lw, l | |||||||||||
return ax | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
As you can see from this chart, economic growth started in earnest in the 18th century and continued for the next two hundred years. | ||||||||||||
|
||||||||||||
|
@@ -280,8 +272,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6)) | |||||||||||
|
||||||||||||
cntry = ['CHN', 'GBR', 'USA'] | ||||||||||||
ax = draw_interp_plots(gdppc[cntry].loc[1500:], | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
|
||||||||||||
# Define the parameters for the events and the text | ||||||||||||
ylim = ax.get_ylim()[1] | ||||||||||||
|
@@ -322,16 +314,14 @@ def draw_events(events, ax): | |||||||||||
event.y_text, event.text, | ||||||||||||
color=event.color, **t_params) | ||||||||||||
ax.axvspan(*event.year_range, color=event.color, alpha=0.2) | ||||||||||||
ax.axvline(event_mid, ymin=1, | ||||||||||||
ymax=event.ymax, color=event.color, | ||||||||||||
linestyle='-', clip_on=False, alpha=0.15) | ||||||||||||
|
||||||||||||
ax.axvline(event_mid, ymin=1, ymax=event.ymax, color=event.color, | ||||||||||||
linestyle='-', clip_on=False, alpha=0.15) | ||||||||||||
|
||||||||||||
# Draw events | ||||||||||||
draw_events(events, ax) | ||||||||||||
plt.show() | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
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 | ||||||||||||
groups of people | ||||||||||||
|
@@ -365,8 +355,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6)) | |||||||||||
|
||||||||||||
cntry = ['CHN'] | ||||||||||||
ax = draw_interp_plots(gdppc[cntry].loc[1600:2000], | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, True, ax) | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, True, ax) | ||||||||||||
|
||||||||||||
ylim = ax.get_ylim()[1] | ||||||||||||
|
||||||||||||
|
@@ -402,7 +392,6 @@ draw_events(events, ax) | |||||||||||
plt.show() | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
We can also look at the United States (USA) and United Kingdom (GBR) in more detail | ||||||||||||
|
||||||||||||
|
@@ -425,8 +414,8 @@ fig, ax = plt.subplots(dpi=300, figsize=(10, 6)) | |||||||||||
|
||||||||||||
cntry = ['GBR', 'USA'] | ||||||||||||
ax = draw_interp_plots(gdppc[cntry].loc[1500:2000], | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, True, ax) | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, True, ax) | ||||||||||||
|
||||||||||||
ylim = ax.get_ylim()[1] | ||||||||||||
|
||||||||||||
|
@@ -463,7 +452,6 @@ draw_events(events, ax) | |||||||||||
plt.show() | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
## The industrialized world | ||||||||||||
|
||||||||||||
|
@@ -478,7 +466,6 @@ data['gdp'] = data['gdppc'] * data['pop'] | |||||||||||
gdp = data['gdp'].unstack('countrycode') | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
### Early industrialization (1820 to 1940) | ||||||||||||
|
||||||||||||
|
@@ -502,11 +489,10 @@ ax = fig.gca() | |||||||||||
cntry = ['CHN', 'SUN', 'JPN', 'GBR', 'USA'] | ||||||||||||
start_year, end_year = (1820, 1945) | ||||||||||||
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year], | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
'International $\'s', 'Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
## Constructing a plot similar to Tooze's | ||||||||||||
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'] | |||||||||||
gdp['BEM'] = gdp[BEM].loc[start_year-1:end_year].interpolate(method='index').sum(axis=1) # Interpolate incomplete time-series | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
Let's take a look at the aggregation that represents the British Empire. | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
gdp['BEM'].plot() # The first year is np.nan due to interpolation | ||||||||||||
gdp['BEM'].plot(ylabel="International $'s") # The first year is np.nan due to interpolation | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line prints out the label We can suppress printing using
Suggested change
or
Suggested change
|
||||||||||||
``` | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
code_to_name | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
Now let's assemble our series and get ready to plot them. | ||||||||||||
|
||||||||||||
|
@@ -549,13 +533,14 @@ ax = fig.gca() | |||||||||||
cntry = ['DEU', 'USA', 'SUN', 'BEM', 'FRA', 'JPN'] | ||||||||||||
start_year, end_year = (1821, 1945) | ||||||||||||
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year], | ||||||||||||
'Real GDP in 2011 $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dpi=300, bbox_inches='tight') | ||||||||||||
'Real GDP in 2011 $\'s', 'Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
|
||||||||||||
plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dpi=300, | ||||||||||||
bbox_inches='tight') | ||||||||||||
plt.show() | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
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 | ||||||||||||
by the end of the 19th century, setting the geopolitical stage for the "American (twentieth) century". | ||||||||||||
|
@@ -580,11 +565,10 @@ ax = fig.gca() | |||||||||||
cntry = ['CHN', 'SUN', 'JPN', 'GBR', 'USA'] | ||||||||||||
start_year, end_year = (1950, 2020) | ||||||||||||
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year], | ||||||||||||
'International $\'s','Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
'International $\'s', 'Year', | ||||||||||||
color_mapping, code_to_name, 2, False, ax) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
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`. | ||||||||||||
|
||||||||||||
|
@@ -595,11 +579,11 @@ We often want to study historical experiences of countries outside the club of " | |||||||||||
Fortunately, the [Maddison Historical Statistics](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) dataset also includes regional aggregations | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header=(0,1,2), index_col=0) | ||||||||||||
data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header=(0,1,2), | ||||||||||||
index_col=0) | ||||||||||||
data.columns = data.columns.droplevel(level=2) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
We can save the raw data in a more convenient format to build a single table of regional GDP per capita | ||||||||||||
|
||||||||||||
|
@@ -608,15 +592,13 @@ regionalgdppc = data['gdppc_2011'].copy() | |||||||||||
regionalgdppc.index = pd.to_datetime(regionalgdppc.index, format='%Y') | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
Let's interpolate based on time to fill in any gaps in the dataset for the purpose of plotting | ||||||||||||
|
||||||||||||
```{code-cell} ipython3 | ||||||||||||
regionalgdppc.interpolate(method='time', inplace=True) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
and record a dataset of world GDP per capita | ||||||||||||
|
||||||||||||
|
@@ -634,13 +616,12 @@ mystnb: | |||||||||||
fig = plt.figure(dpi=300) | ||||||||||||
ax = fig.gca() | ||||||||||||
ax = worldgdppc.plot( | ||||||||||||
ax = ax, | ||||||||||||
ax=ax, | ||||||||||||
xlabel='Year', | ||||||||||||
ylabel='2011 US$', | ||||||||||||
) | ||||||||||||
``` | ||||||||||||
|
||||||||||||
+++ {"user_expressions": []} | ||||||||||||
|
||||||||||||
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. | ||||||||||||
|
||||||||||||
|
@@ -656,9 +637,10 @@ mystnb: | |||||||||||
fig = plt.figure(dpi=300) | ||||||||||||
ax = fig.gca() | ||||||||||||
line_styles = ['-', '--', ':', '-.', '.', 'o', '-', '--', '-'] | ||||||||||||
ax = regionalgdppc.plot(ax = ax, style=line_styles) | ||||||||||||
ax = regionalgdppc.plot(ax=ax, xlabel='Year', | ||||||||||||
ylabel='2011 US$', style=line_styles) | ||||||||||||
ax.set_yscale('log') | ||||||||||||
plt.legend(loc='lower center', | ||||||||||||
ncol=3, bbox_to_anchor=[0.5, -0.4]) | ||||||||||||
plt.legend(loc='lower center', | ||||||||||||
ncol=3, bbox_to_anchor=[0.5, -0.4]) | ||||||||||||
plt.show() | ||||||||||||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line is also a bit too long. I suggest we can cut it to this: