I have a plot that looks like this :
import pandas as pd
import pandas_datareader as web
import datetime as dt
from datetime import timedelta
import matplotlib.pyplot as plt
#get the data
start_date = pd.to_datetime('2019-11-1')
end_date = pd.datetime.today()
df = web.DataReader('^gspc', 'yahoo', start_date, end_date)
df = df['Adj Close']
#build the plot
fig, ax1 = plt.subplots()
ax1.plot(df)
#set the axhline
ax1.axhline(df.max(),xmin=0,xmax=1)
ax1.set_xlim(start_date,end_date + timedelta(30))
ax1.set_ylim(df.min() -200, df.max() +200)
I am trying to set the axhline so it starts on the day of the maximum value in the df. I am having issues because the index is a datetime object, and axhline needs an integer.
Here is what I've tried:
ax1.axhline(df.max(),xmin=df.idxmax(),xmax=1)
What is the most efficient way to set the xmin to the date of the max value in the df?
Thanks
