Jun-08-2023, 10:58 PM
I'm struggling to figure out how to create multiple vertical rectangles that span entire plots using plotly.
I'm assuming this is possible using add_vrect()?
Below is the code that I want to add the vertical rectangles to – with the hope of spanning all of the dates corresponding with the "Recession" periods found in the attached data set.
Any help would be greatly appreciated.
I'm assuming this is possible using add_vrect()?
Below is the code that I want to add the vertical rectangles to – with the hope of spanning all of the dates corresponding with the "Recession" periods found in the attached data set.
Any help would be greatly appreciated.
import pandas as pd
import plotly.graph_objects as go
import datetime
# Load data
history = pd.read_csv("sample_data.csv")
history["Date"] = pd.to_datetime(history["Date"], format="%Y-%m-%d")
history.set_index("Date", inplace=True)
# Filter out recession dates
recession = history.loc[history["Regime"] == "Recession"].index
# Plot DJI
fig = go.Figure()
fig.add_trace(go.Scatter(x=history.index, y=history["DJI"], mode="lines"))
# Show plot
fig.show()
Attached Files
