I am trying to reconstruct a time series graphs from FRED: https://fred.stlouisfed.org/series/LABSHPUSA156NRUG using Python. However, I am unable to get a clean figure where the time series is overlaid with the area graph representing the recession bars.
I am quite new to python so it's been frustrating to find a simple reason why my attempts are not working.
I have attempted this two ways.
My first attempt looks like this:
fig, ax = plt.subplots() ls_data.plot.line(ax=ax, figsize=(8,5), x='Date', color=blue) rec_data.plot.area(ax=ax, figsize=(8,5), x='Date', alpha=0.5, color=gray) plt.ylim(0.59,0.65)
My second attempt goes for the "ax2 = ax1.twinx()" route
fig, ax1 = plt.subplots() ax2 = ax1.twinx() ls_data.plot.line(figsize=(8,5), x='Date', color=blue) rec_data.plot.area(figsize=(8,5), x='Date', alpha=0.5, color=gray)
However this produces two separate figures instead.
One possible issue is that the x-values for the labor share are plotted in individual years whereas the x-values for recession are plotted in months. But based on the second attempt, it looks like the graphs should overlay smoothly but then I'm liable to get the same result as in my first attempt. Would transforming the recession data provide a fix?
Edit: The data for recession dates are available here. https://fred.stlouisfed.org/series/USREC#:~:text=For%20daily%20data%2C%20the%20recession,the%20month%20of%20the%20trough.