Second y-axis time series seaborn

后端 未结 2 618
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 01:50

Using the data frame

df = pd.DataFrame({
    \"date\" : [\"2018-01-01\", \"2018-01-02\", \"2018-01-03\", \"2018-01-04\"],
    \"column1\" : [555,525,532,585]         


        
相关标签:
2条回答
  • 2020-12-29 02:32

    I would recommend using a normal line plot. You can get a twin axes via ax.twinx().

    import pandas as pd
    import matplotlib.pyplot as plt
    
    df = pd.DataFrame({"date": ["2018-01-01", "2018-01-02", "2018-01-03", "2018-01-04"],
                       "column1": [555,525,532,585], 
                       "column2": [50,48,49,51]})
    
    ax = df.plot(x="date", y="column1", legend=False)
    ax2 = ax.twinx()
    df.plot(x="date", y="column2", ax=ax2, legend=False, color="r")
    ax.figure.legend()
    plt.show()
    

    0 讨论(0)
  • 2020-12-29 02:47

    As seaborn is built on the top of matplotlib, you can use its power:

    import matplotlib.pyplot as plt
    sns.lineplot(data=df.column1, color="g")
    ax2 = plt.twinx()
    sns.lineplot(data=df.column2, color="b", ax=ax2)
    
    0 讨论(0)
提交回复
热议问题