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

后端 未结 4 1474
花落未央
花落未央 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:15

    DataFrame plot function returns AxesSubplot object and on it, you can add as many lines as you want. Take a look at the code sample below:

    %matplotlib inline
    
    import pandas as pd
    import numpy as np
    
    df = pd.DataFrame(index=pd.date_range("2019-07-01", "2019-07-31"))  # for sample data only
    df["y"] = np.logspace(0, 1, num=len(df))  # for sample data only
    
    ax = df.plot()
    # you can add here as many lines as you want
    ax.axhline(6, color="red", linestyle="--")
    ax.axvline("2019-07-24", color="red", linestyle="--")
    

提交回复
热议问题