1

I'm trying to create a vertical line on specific date, which is not part of my df weekly date index, and since it's not in the index, the plot is locating the vertical line on the next date that in the df index:

df=pd.DataFrame(index=pd.date_range('2020-01-01','2020-05-01',freq='W'),data={'val':range(0,17)})
ax=df.plot(grid=True,figsize=(12,6))
ax.set_xticks(df.index)
ax.set_xticklabels([x.date() for x in df.index],rotation=90)
ax.axvline(pd.Timestamp('2020-03-03'),ls='--',color='k')

enter image description here

as you can see, although I want to draw the line on '2020-03-03', it's created on '2020-03-08'.

Any ideas here? thanks :)

David
  • 871
  • 1
  • 5
  • 13
  • Have you tried simply adding "2020-03-03" to your sample? As you could easily interpolate the y value. – TiTo May 06 '20 at 11:19
  • I need this for something more complicated that will be hard to interpolate – David May 06 '20 at 11:23

1 Answers1

1

I was able to solve this using matplotlib instead of pandas plot

import matplotlib.pyplot as plt
fig,ax=plt.subplots(1,1,figsize=(12,6))
ax.plot(df)

ax.set_xticks(df.index)
ax.set_xticklabels([x.date() for x in df.index],rotation=90)
ax.axvline(pd.Timestamp('2020-03-03'),ls='--',color='k')

enter image description here

David
  • 871
  • 1
  • 5
  • 13