I have a problem setting axvline over my plot for dataframe.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 159 entries, 0 to 158
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 index 159 non-null int64
1 Year 159 non-null int64
2 Week 159 non-null object
3 Week_Number 159 non-null int64
4 Week_Start 159 non-null datetime64[ns]
5 Incidents 159 non-null int64
dtypes: datetime64[ns](1), int64(4), object(1)
This is my code:
from pandas import DataFrame
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(20, 4))
df=Alldata
Year=Alldata['Year']
Week=Alldata['Week']
Week_Number=Alldata['Week_Number']
Week_Start=Alldata['Week_Start']
Incidents=Alldata['Incidents']
Dataset = list(zip(Year, Week, Week_Number,Week_Start, Incidents))
df = DataFrame(data = Dataset, columns = ['Year', 'Week', 'Week_Number','Week_Start', 'Incidents'])
df['Incidents'].plot(legend = True, label = 'Incidents')
plt.xticks(df.index,df["Week_Start"].values)
unique_years, ind = np.unique(df["Year"].values,return_index=True)
plt.xticks(df.index[ind], unique_years)
#ax.axvline(pd.to_datetime('2020-03-18'), color='r', linestyle='--', lw=2)
#ax.axvline(pd.to_datetime('2021-06-05'), color='b', linestyle='--', lw=2)
plt.show()
For some reason I get a graph like this:
Without my axvline, I get a normal graph as desired:
Could someone please help me with my axvline?