Skip to content

Commit f6e8573

Browse files
committed
add plots on monthly inflation rate
1 parent e7f0cc5 commit f6e8573

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

lectures/inflation_history.md

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def process_df(df):
250250
251251
return df
252252
253-
def create_plot(p_seq, e_seq, index, labs, ax):
253+
def create_pe_plot(p_seq, e_seq, index, labs, ax):
254254
255255
p_lab, e_lab = labs
256256
@@ -273,6 +273,28 @@ def create_plot(p_seq, e_seq, index, labs, ax):
273273
ax1.legend(loc='upper left')
274274
275275
return ax1
276+
277+
def create_pr_plot(p_seq, index, ax):
278+
279+
# Calculate the difference of log p_seq
280+
log_diff_p_seq = np.diff(np.log(p_seq))
281+
282+
# Graph for the difference of log p_seq
283+
ax.scatter(index[1:], log_diff_p_seq, label='Monthly Inflation Rate', color='tab:grey')
284+
diff_smooth = pd.DataFrame(log_diff_p_seq).rolling(3).mean()
285+
ax.plot(index[1:], diff_smooth, alpha=0.5, color='tab:grey')
286+
ax.text(-0.08, 1.03, 'Monthly Inflation Rate', transform=ax.transAxes)
287+
288+
ax.xaxis.set_major_locator(mdates.MonthLocator(interval=5))
289+
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))
290+
291+
for label in ax.get_xticklabels():
292+
label.set_rotation(45)
293+
294+
ax.legend(loc='upper left')
295+
296+
return ax
297+
276298
```
277299

278300
```{code-cell} ipython3
@@ -319,13 +341,21 @@ lab = ['Retail Price Index', 'Exchange Rate']
319341
320342
# create plot
321343
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
322-
_ = create_plot(p_seq, e_seq, df_Aus.index, lab, ax)
344+
_ = create_pe_plot(p_seq, e_seq, df_Aus.index, lab, ax)
323345
324346
# connect disjunct parts
325347
plt.figtext(0.5, -0.02, 'Austria', horizontalalignment='center', fontsize=12)
326348
plt.show()
327349
```
328350

351+
```{code-cell} ipython3
352+
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
353+
_ = create_pr_plot(p_seq, df_Aus.index, ax)
354+
355+
plt.figtext(0.5, -0.02, 'Austria', horizontalalignment='center', fontsize=12)
356+
plt.show()
357+
```
358+
329359
### Hungary
330360

331361
The source of our data for Hungary is:
@@ -346,7 +376,15 @@ lab = ['Hungarian Index of Prices', '1/Cents per Crown in New York']
346376
347377
# create plot
348378
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
349-
_ = create_plot(p_seq, e_seq, df_Hung.index, lab, ax)
379+
_ = create_pe_plot(p_seq, e_seq, df_Hung.index, lab, ax)
380+
381+
plt.figtext(0.5, -0.02, 'Hungary', horizontalalignment='center', fontsize=12)
382+
plt.show()
383+
```
384+
385+
```{code-cell} ipython3
386+
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
387+
_ = create_pr_plot(p_seq, df_Hung.index, ax)
350388
351389
plt.figtext(0.5, -0.02, 'Hungary', horizontalalignment='center', fontsize=12)
352390
plt.show()
@@ -398,7 +436,15 @@ lab = ['Wholesale Price Index', '1/Cents per Polish Mark']
398436
399437
# create plot
400438
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
401-
ax1 = create_plot(p_seq, e_seq, df_Pol.index, lab, ax)
439+
ax1 = create_pe_plot(p_seq, e_seq, df_Pol.index, lab, ax)
440+
441+
plt.figtext(0.5, -0.02, 'Poland', horizontalalignment='center', fontsize=12)
442+
plt.show()
443+
```
444+
445+
```{code-cell} ipython3
446+
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
447+
_ = create_pr_plot(p_seq, df_Pol.index, ax)
402448
403449
plt.figtext(0.5, -0.02, 'Poland', horizontalalignment='center', fontsize=12)
404450
plt.show()
@@ -423,7 +469,7 @@ lab = ['Price Index', '1/Cents per Mark']
423469
424470
# create plot
425471
fig, ax = plt.subplots(figsize=[9,5], dpi=200)
426-
ax1 = create_plot(p_seq, e_seq, df_Germ.index, lab, ax)
472+
ax1 = create_pe_plot(p_seq, e_seq, df_Germ.index, lab, ax)
427473
428474
plt.figtext(0.5, -0.06, 'Germany', horizontalalignment='center', fontsize=12)
429475
plt.show()
@@ -441,7 +487,15 @@ lab = ['Price Index (Marks or converted to Marks)', '1/Cents per Mark (or Reichs
441487
442488
# create plot
443489
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
444-
ax1 = create_plot(p_seq, e_seq, df_Germ.index, lab, ax)
490+
ax1 = create_pe_plot(p_seq, e_seq, df_Germ.index, lab, ax)
491+
492+
plt.figtext(0.5, -0.02, 'Germany', horizontalalignment='center', fontsize=12)
493+
plt.show()
494+
```
495+
496+
```{code-cell} ipython3
497+
fig, ax = plt.subplots(figsize=[10,7], dpi=200)
498+
_ = create_pr_plot(p_seq, df_Germ.index, ax)
445499
446500
plt.figtext(0.5, -0.02, 'Germany', horizontalalignment='center', fontsize=12)
447501
plt.show()

0 commit comments

Comments
 (0)