How do you plot a vertical line on a time series plot in Pandas?
plt.axvline(x_position)
It takes the standard plot formatting options (linestlye
, color
, ect)
(doc)
If you have a reference to your axes
object:
ax.axvline(x, color='k', linestyle='--')
If you have a time-axis, and you have Pandas imported as pd, you can use:
ax.axvline(pd.to_datetime('2015-11-01'), color='r', linestyle='--', lw=2)
For multiple lines:
xposition = [pd.to_datetime('2010-01-01'), pd.to_datetime('2015-12-31')]
for xc in xposition:
ax.axvline(x=xc, color='k', linestyle='-')