My data is stored as a pandas dataframe. I have created a chart of date (object format) vs. percentile (int64 format) using the plot_date() function in matplotlib and would like to add some vertical lines at pre-specified dates.
I have managed to add point markers at the pre-specified dates, but can't seem to find a way to make them into vertical lines.
I've found various answers on SO/SE about how to add vertical lines to a plot(), but am having trouble converting my data to a format that can be used by plot(), hence why I have used plot_date().
Sample data:
date percentile
2012-05-30 3
2014-11-25 60
2012-06-15 38
2013-07-18 16
My code to plot the chart is as below:
x_data = data["date"]
y_data = data["percentile"]
plt.figure()
plt.plot()
#create a scatter chart of dates vs. percentile
plt.plot_date(x = x_data, y = y_data)
#now add a marker at prespecified dates - ideally this would be a vertical line
plt.plot_date(x = '2012-09-21', y = 0)
plt.savefig("percentile_plot.png")
plt.close()
Unfortunately I can't provide an image of the current output as the code is on a terminal with no web access.
Any help is greatly appreciated - also in terms of how I've asked the question as I am quite new to SO / SE.
Thank you.