简体   繁体   中英

axvline on a specific date - weekly data

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')

在此处输入图像描述

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:)

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')

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM