Skip to content

Instantly share code, notes, and snippets.

@TJConnellyContingentMacro
Forked from TomAugspurger/add_rec_bars.py
Created September 18, 2018 15:31
Show Gist options
  • Save TJConnellyContingentMacro/eb7fd114a032c1619503724b67e771b0 to your computer and use it in GitHub Desktop.
Save TJConnellyContingentMacro/eb7fd114a032c1619503724b67e771b0 to your computer and use it in GitHub Desktop.
Adding recession bars to matplotlib axes.
import pandas as pd
def add_rec_bars(ax, dates=None):
if dates is None:
dates = pd.read_csv('/Users/tom/bin/rec_dates.csv',
parse_dates=['Peak', 'Trough'])
for row in dates.iterrows():
x = row[1]
y1, y2 = ax.get_ylim()
ax.fill_between(x, y1=y1, y2=y2, alpha=.25, color='k')
return ax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment