How do you plot a vertical line on a time series plot in Pandas?

后端 未结 4 1478
花落未央
花落未央 2020-11-28 22:56
  • How do you plot a vertical line (vlines) in a Pandas series plot?
  • I am using Pandas to plot rolling means, etc., and would like to mark important
4条回答
  •  一向
    一向 (楼主)
    2020-11-28 23:26

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

提交回复
热议问题