Skip to content

Commit c2f0f74

Browse files
committed
simplfiy matplotlib config + migrate fig text to labels
1 parent e22b9de commit c2f0f74

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lectures/inflation_history.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ We can then import the Python modules we will use.
2828
import numpy as np
2929
import pandas as pd
3030
import matplotlib.pyplot as plt
31-
plt.matplotlib.rcParams['figure.figsize'] = (12,8)
32-
plt.rcParams.update({'font.size': 19})
3331
import matplotlib.dates as mdates
3432
```
3533

@@ -102,10 +100,9 @@ for col in cols:
102100
103101
ax.legend()
104102
ax.set_ylabel('Index 1913 = 100')
103+
ax.set_xlabel('Year')
105104
ax.set_xlim(xmin=1600)
106105
plt.tight_layout()
107-
fig.text(.5, .0001,
108-
"Price levels", ha='center')
109106
plt.show()
110107
```
111108

@@ -171,11 +168,10 @@ for col in cols:
171168
172169
ax.set_yscale('log')
173170
ax.set_ylabel('Index 1913 = 100')
174-
ax.set_xlim(xmin=1600)
175171
ax.set_ylim([10, 1e6])
172+
ax.set_xlabel('Logs of price levels')
173+
ax.set_xlim(xmin=1600)
176174
plt.tight_layout()
177-
fig.text(.5, .0001,
178-
"Logs of price levels", ha='center')
179175
plt.show()
180176
```
181177

@@ -305,9 +301,9 @@ def pe_plot(p_seq, e_seq, index, labs, ax):
305301
label.set_rotation(45)
306302
307303
# set labels
308-
ax.text(-0.08, 1.03, 'Price level', transform=ax.transAxes)
309-
ax.text(0.92, 1.03, 'Exchange rate', transform=ax.transAxes)
310-
304+
ax.set_ylabel('Price level')
305+
ax1.set_ylabel('Exchange rate')
306+
311307
ax1.legend(loc='upper left')
312308
313309
return ax1
@@ -326,9 +322,7 @@ def pr_plot(p_seq, index, ax):
326322
# calculate and plot moving average
327323
diff_smooth = pd.DataFrame(log_diff_p).rolling(3, center=True).mean()
328324
ax.plot(index[1:], diff_smooth, label='Moving average (3 period)', alpha=0.5, lw=2)
329-
ax.text(-0.08, 1.03,
330-
'Monthly inflation rate',
331-
transform=ax.transAxes)
325+
ax.set_ylabel('Inflation rate')
332326
333327
ax.xaxis.set_major_locator(
334328
mdates.MonthLocator(interval=5))

0 commit comments

Comments
 (0)