I was trying to do something simple: plot some bar plots and add a vertical line, for a dataframe like this:
index data
2021-06-05 14628.0
2021-06-06 1969.0
2021-06-07 50918.0
And doing this:
df.data.plot.bar()
plt.axvline('20210606')
To my surprise, this only works on df[col].plot()
but not on df[col].plot.bar()
. I tried figuring it out and I found I could manage to plot my line by finding what x data matplotlib's actually getting:
ax = plt.gca()
rectangles = ax.patches
plt.axvline((rectangles[1].get_x() + rectangles[1].get_width()/2), color='r')
Which brings the desired plot, but in a very non-straightforward way. Is there any way to achieve this by actually using dates or should I get used to ax.patches
?
Thanks !