Feb-22-2023, 08:14 PM
Hi,
I am trying to figure out how to create a graph similar to the following:
![[Image: LHt8r.png]](https://i.stack.imgur.com/LHt8r.png)
where the x axis has the monthly time data and the y axis represents the Dow Jones average (DJI column on my sample data). I am trying to get the recession months to plot as vertical bars corresponding to the "Regime" column in my sample data.
Here is the code; files are also attached – any help would be greatly appreciated:
I am trying to figure out how to create a graph similar to the following:
![[Image: LHt8r.png]](https://i.stack.imgur.com/LHt8r.png)
where the x axis has the monthly time data and the y axis represents the Dow Jones average (DJI column on my sample data). I am trying to get the recession months to plot as vertical bars corresponding to the "Regime" column in my sample data.
Here is the code; files are also attached – any help would be greatly appreciated:
import pandas as pd
import plotly.graph_objects as go
import matplotlib as mpl
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import datetime
from datetime import date
import numpy as np
#import data
history = pd.read_csv("sample_data.csv")
history = history.replace(np. nan,'',regex = True)
#filter out recession dates
recession = history.loc[history["Regime"] == "Recession", "Date"]
#plot axvspan for every recession month
for month in recession:
plt.axvspan(recession, recession + datetime.timedelta(days=1), color="grey", alpha=0.5)
plt.show()
Attached Files
