from pandas_datareader import data, wb
import pandas_datareader as pdr
import matplotlib.pyplot as plt
import datetime as dt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters() # Allow matplotlib have access to timestamp
import matplotlib.ticker as mplticker
# Retrieve data from FRED, check my notebook for pandareader's user guide
start = dt.datetime(2000, 1, 1)
end = dt.datetime.today()
HDtoGDP = pdr.data.DataReader('HDTGPDUSQ163N', 'fred', start, end) # Household Debt to GDP for United States
GDP_growth = pdr.data.DataReader('A191RL1Q225SBEA', 'fred', start, end)
HDtoGDP = HDtoGDP.pct_change()
fig, ax = plt.subplots(figsize = (13, 8))
ax.plot(HDtoGDP*100, label = 'Change of Household Debt Ratio')
ax.plot(GDP_growth, label = 'GDP Growth')
ax.legend()
alp = .3
ax.axvspan('2007-12-1','2009-6-1',color = 'gray', alpha = alp, zorder = -1)
ax.axvspan('2020-3-1','2020-6-1',color = 'gray', alpha = alp, zorder = -1)
ax.yaxis.grid(True) # only horizontal grid
plt.show()