I am trying to plot dates (N=50) on a 5 year time series chart and I'm having trouble trying to figure out how to run through an iteration on a for loop. Below is an example of what I'm trying to plot the dates on.
Visual of what I'm plotting dates on
Currently, I am trying:
for date in dataframe_with_dates.DATE:
plt.axvline(x = date, color = 'g')
plt.show()
and I'm receiving an error of:
Failed to convert value(s) to axis units: 'DATE'
I'm not sure if this has something to do with the dtype being datetime, or if I need to try another approach, but any advice/guidance is greatly appreciated!
Thank you!
This is what I am trying to accomplish: Example image
EDIT: Code to produce the plot
def plot_df(df_1, x, y, title = '', xlabel = 'DATE', ylabel = 'VALUE', dpi = 100):
plt.figure(figsize = (25,5), dpi = dpi)
plt.plot(x, y, color = 'tab:red')
plt.gca().set(title = title, xlabel = xlabel, ylabel = ylabel)
plt.show()
plot_df(df_VIX, x = df_VIX.DATE, y = df_VIX.AVG_VALUE, title = 'Daily VIX since 1990')
`
data_test = [['2016-01-04', 22.48, 23.36, 20.67, 20.70, 21.8025],
['2016-01-05', 20.75, 21.06, 19.25, 19.34, 20.1],
['2016-01-06', 21.67, 21.86, 19.8, 20.59, 20.98],
['2016-01-07', 23.22, 25.86, 22.4, 24.99, 24.1175],
['2016-01-08', 22.96, 25.86, 22.40, 24.99, 24.89]]
df_test = pd.DataFrame(data_test, columns = ['DATE','OPEN','HIGH','LOW','CLOSE', 'AVG_VALUE'])
df_test['DATE'] = pd.to_datetime(df_test['DATE'])
This will reproduce a sample of the exact data I'm using.