@@ -139,6 +139,7 @@ mystnb:
139139 figure:
140140 caption: GDP per Capita (GBR)
141141 name: gdppc_gbr1
142+ width: 500px
142143---
143144fig, ax = plt.subplots(dpi=300)
144145cntry = 'GBR'
@@ -187,15 +188,18 @@ We can now put this into a function to generate plots for a list of countries
187188def draw_interp_plots(series, xlabel, ylabel, color_mapping, code_to_name, lw, logscale, ax):
188189
189190 for i, c in enumerate(cntry):
190-
191+ # Get the interpolated data
191192 df_interpolated = series[c].interpolate(limit_area='inside')
192193 interpolated_data = df_interpolated[series[c].isnull()]
194+
195+ # Plot the interpolated data with dashed lines
193196 ax.plot(interpolated_data,
194197 linestyle='--',
195198 lw=lw,
196199 alpha=0.7,
197200 color=color_mapping[c])
198201
202+ # Plot the non-interpolated data with solid lines
199203 ax.plot(series[c],
200204 linestyle='-',
201205 lw=lw,
@@ -205,7 +209,8 @@ def draw_interp_plots(series, xlabel, ylabel, color_mapping, code_to_name, lw, l
205209
206210 if logscale == True:
207211 ax.set_yscale('log')
208-
212+
213+ # Draw the legend outside the plot
209214 ax.legend(loc='lower center', ncol=5, bbox_to_anchor=[0.5, -0.25])
210215 ax.set_xlabel(xlabel)
211216 ax.set_ylabel(ylabel)
@@ -226,30 +231,52 @@ How does this compare with other countries' growth trajectories?
226231Let's look at the United States (USA), United Kingdom (GBR), and China (CHN)
227232
228233``` {code-cell} ipython3
234+ ---
235+ mystnb:
236+ figure:
237+ caption: GDP per Capita (China, UK, USA)
238+ name: gdppc_comparison
239+ ---
240+
241+ # Define the namedtuple for the events
229242Event = namedtuple('Event', ['year_range', 'y_text', 'text', 'color', 'ymax'])
230243
231- fig, ax = plt.subplots(dpi=300)
244+ fig, ax = plt.subplots(dpi=300, figsize=(10, 6) )
232245
233246cntry = ['CHN', 'GBR', 'USA']
234- ax = draw_interp_plots(gdppc[cntry].loc[1200 :],
247+ ax = draw_interp_plots(gdppc[cntry].loc[1500 :],
235248 'International $\'s','Year',
236- color_mapping, code_to_name, 2, True , ax)
249+ color_mapping, code_to_name, 2, False , ax)
237250
251+ # Define the parameters for the events and the text
238252ylim = ax.get_ylim()[1]
239253b_params = {'color':'grey', 'alpha': 0.2}
240- t_params = {'fontsize': 5 ,
254+ t_params = {'fontsize': 9 ,
241255 'va':'center', 'ha':'center'}
242256
257+ # Create a list of events to annotate
243258events = [
244- Event((1315, 1321), ylim + ylim*0.1, 'the Great Famine\n(1315-1321)', color_mapping['GBR'], 1),
245- Event((1348, 1375), ylim + ylim*0.4, 'the Black Death\n(1348-1375)', color_mapping['GBR'], 1.05),
246- Event((1650, 1652), ylim + ylim*0.1, 'the Navigation Act\n(1651)', color_mapping['GBR'], 1),
247- Event((1848, 1850), ylim + ylim*0.8, 'the Repeal of Navigation Act\n(1849)', color_mapping['GBR'], 1.1),
248- Event((1655, 1684), ylim + ylim*0.4, 'Closed-door Policy\n(1655-1684)', color_mapping['CHN'], 1.05),
249- Event((1760, 1840), ylim + ylim*0.4, 'Industrial Revolution\n(1760-1840)', 'grey', 1.05),
250- Event((1788, 1790), ylim + ylim*0.1, 'US Federation\n(1789)', color_mapping['USA'], 1),
251- Event((1929, 1939), ylim + ylim*0.1, 'the Great Depression\n(1929–1939)', 'grey', 1),
252- Event((1978, 1979), ylim + ylim*0.4, 'Reform and Opening-up\n(1978-1979)', color_mapping['CHN'], 1.05)
259+ Event((1650, 1652), ylim + ylim*0.04,
260+ 'the Navigation Act\n(1651)',
261+ color_mapping['GBR'], 1),
262+ Event((1655, 1684), ylim + ylim*0.13,
263+ 'Closed-door Policy\n(1655-1684)',
264+ color_mapping['CHN'], 1.1),
265+ Event((1848, 1850), ylim + ylim*0.22,
266+ 'the Repeal of Navigation Act\n(1849)',
267+ color_mapping['GBR'], 1.18),
268+ Event((1765, 1791), ylim + ylim*0.04,
269+ 'American Revolution\n(1765-1791)',
270+ color_mapping['USA'], 1),
271+ Event((1760, 1840), ylim + ylim*0.13,
272+ 'Industrial Revolution\n(1760-1840)',
273+ 'grey', 1.1),
274+ Event((1929, 1939), ylim + ylim*0.04,
275+ 'the Great Depression\n(1929–1939)',
276+ 'grey', 1),
277+ Event((1978, 1979), ylim + ylim*0.13,
278+ 'Reform and Opening-up\n(1978-1979)',
279+ color_mapping['CHN'], 1.1)
253280]
254281
255282def draw_events(events, ax):
@@ -260,13 +287,17 @@ def draw_events(events, ax):
260287 event.y_text, event.text,
261288 color=event.color, **t_params)
262289 ax.axvspan(*event.year_range, color=event.color, alpha=0.2)
263- ax.axvline(event_mid, ymin=1, ymax=event.ymax, color=event.color, linestyle='-', clip_on=False, alpha=0.15)
290+ ax.axvline(event_mid, ymin=1,
291+ ymax=event.ymax, color=event.color,
292+ linestyle='-', clip_on=False, alpha=0.15)
264293
265294# Draw events
266295draw_events(events, ax)
267296plt.show()
268297```
269298
299+ +++ {"user_expressions": [ ] }
300+
270301(TODO: Finalize trend)
271302We can see some interesting trends:
272303
@@ -284,27 +315,50 @@ Trends to note:
284315- Period of economic downturn after the Closed-door Policy by the Qing government
285316- Missing out on the industrial revolution
286317- Self-Strengthening Movement may help the growth but in a very mild way
287- - Modern Chinese economic policies and the growth after the founding of the PRC (political stability) and after the Reform and Opening-up
318+ - Modern Chinese economic policies and the growth after the founding of the PRC (political stability) and after the Reform and Opening-up
288319
289320``` {code-cell} ipython3
290- fig, ax = plt.subplots(dpi=300)
321+ ---
322+ mystnb:
323+ figure:
324+ caption: GDP per Capita (China)
325+ name: gdppc_china
326+ ---
327+
328+ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
329+
291330cntry = ['CHN']
292331ax = draw_interp_plots(gdppc[cntry].loc[1600:2000],
293332 'International $\'s','Year',
294333 color_mapping, code_to_name, 2, True, ax)
295334
296- # Define the namedtuple for the data points
297335ylim = ax.get_ylim()[1]
298336
299337events = [
300- Event((1655, 1684), ylim + ylim*0.05, 'Closed-door Policy\n(1655-1684)', 'tab:orange', 1),
301- Event((1760, 1840), ylim + ylim*0.05, 'Industrial Revolution\n(1760-1840)', 'grey', 1),
302- Event((1839, 1842), ylim + ylim*0.15, 'First Opium War\n(1839–1842)', 'tab:red', 1.05),
303- Event((1861, 1895), ylim + ylim*0.25, 'Self-Strengthening Movement\n(1861–1895)', 'tab:blue', 1.09),
304- Event((1939, 1945), ylim + ylim*0.05, 'WW 2\n(1939-1945)', 'tab:red', 1),
305- Event((1948, 1950), ylim + ylim*0.2, 'Founding of PRC\n(1949)', color_mapping['CHN'], 1.07),
306- Event((1958, 1962), ylim + ylim*0.35, 'Great Leap Forward\n(1958-1962)', 'tab:orange', 1.13),
307- Event((1978, 1979), ylim + ylim*0.5, 'Reform and Opening-up\n(1978-1979)', 'tab:blue', 1.18)
338+ Event((1655, 1684), ylim + ylim*0.06,
339+ 'Closed-door Policy\n(1655-1684)',
340+ 'tab:orange', 1),
341+ Event((1760, 1840), ylim + ylim*0.06,
342+ 'Industrial Revolution\n(1760-1840)',
343+ 'grey', 1),
344+ Event((1839, 1842), ylim + ylim*0.2,
345+ 'First Opium War\n(1839–1842)',
346+ 'tab:red', 1.07),
347+ Event((1861, 1895), ylim + ylim*0.4,
348+ 'Self-Strengthening Movement\n(1861–1895)',
349+ 'tab:blue', 1.14),
350+ Event((1939, 1945), ylim + ylim*0.06,
351+ 'WW 2\n(1939-1945)',
352+ 'tab:red', 1),
353+ Event((1948, 1950), ylim + ylim*0.23,
354+ 'Founding of PRC\n(1949)',
355+ color_mapping['CHN'], 1.08),
356+ Event((1958, 1962), ylim + ylim*0.5,
357+ 'Great Leap Forward\n(1958-1962)',
358+ 'tab:orange', 1.18),
359+ Event((1978, 1979), ylim + ylim*0.7,
360+ 'Reform and Opening-up\n(1978-1979)',
361+ 'tab:blue', 1.24)
308362]
309363
310364# Draw events
@@ -322,8 +376,15 @@ Trends to note:
322376- Wars and business cycles (link to business cycles lecture)
323377
324378``` {code-cell} ipython3
325- # Create the plot
326- fig, ax = plt.subplots(dpi=300)
379+ ---
380+ mystnb:
381+ figure:
382+ caption: GDP per Capita (UK and US)
383+ name: gdppc_china
384+ ---
385+
386+
387+ fig, ax = plt.subplots(dpi=300, figsize=(10, 6))
327388
328389cntry = ['GBR', 'USA']
329390ax = draw_interp_plots(gdppc[cntry].loc[1500:2000],
@@ -334,21 +395,39 @@ ylim = ax.get_ylim()[1]
334395
335396# Create a list of data points=
336397events = [
337- Event((1651, 1651), ylim + ylim*0.1, 'Navigation Act (UK)\n(1651)', 'tab:orange', 1),
338- Event((1788, 1790), ylim + ylim*0.4, 'Federation (US)\n(1789)', color_mapping['USA'], 1.055),
339- Event((1760, 1840), ylim + ylim*0.1, 'Industrial Revolution\n(1760-1840)', 'grey', 1),
340- Event((1848, 1850), ylim + ylim*0.6, 'Repeal of Navigation Act (UK)\n(1849)', 'tab:blue', 1.085),
341- Event((1861, 1865), ylim + ylim*1, 'American Civil War (US)\n(1861-1865)', color_mapping['USA'], 1.14),
342- Event((1914, 1918), ylim + ylim*0.1, 'WW 1\n(1914-1918)', 'tab:red', 1),
343- Event((1929, 1939), ylim + ylim*0.4, 'the Great Depression\n(1929–1939)', 'grey', 1.06),
344- Event((1939, 1945), ylim + ylim*0.8, 'WW 2\n(1939-1945)', 'tab:red', 1.11)
398+ Event((1651, 1651), ylim + ylim*0.15,
399+ 'Navigation Act (UK)\n(1651)',
400+ 'tab:orange', 1),
401+ Event((1765, 1791), ylim + ylim*0.15,
402+ 'American Revolution\n(1765-1791)',
403+ color_mapping['USA'], 1),
404+ Event((1760, 1840), ylim + ylim*0.6,
405+ 'Industrial Revolution\n(1760-1840)',
406+ 'grey', 1.08),
407+ Event((1848, 1850), ylim + ylim*1.1,
408+ 'Repeal of Navigation Act (UK)\n(1849)',
409+ 'tab:blue', 1.14),
410+ Event((1861, 1865), ylim + ylim*1.8,
411+ 'American Civil War\n(1861-1865)',
412+ color_mapping['USA'], 1.21),
413+ Event((1914, 1918), ylim + ylim*0.15,
414+ 'WW 1\n(1914-1918)',
415+ 'tab:red', 1),
416+ Event((1929, 1939), ylim + ylim*0.6,
417+ 'the Great Depression\n(1929–1939)',
418+ 'grey', 1.08),
419+ Event((1939, 1945), ylim + ylim*1.1,
420+ 'WW 2\n(1939-1945)',
421+ 'tab:red', 1.14)
345422]
346423
347424# Draw events
348425draw_events(events, ax)
349426plt.show()
350427```
351428
429+ +++ {"user_expressions": [ ] }
430+
352431## The Industrialized World
353432
354433(TODO: Write description for this section)
@@ -509,6 +588,7 @@ ax = fig.gca()
509588line_styles = ['-', '--', ':', '-.', '.', 'o', '-', '--', '-']
510589ax = regionalgdppc.plot(ax = ax, style=line_styles)
511590ax.set_yscale('log')
512- plt.legend(loc='lower center', ncol=3, bbox_to_anchor=[0.5, -0.4])
591+ plt.legend(loc='lower center',
592+ ncol=3, bbox_to_anchor=[0.5, -0.4])
513593plt.show()
514594```
0 commit comments