Adding a y-axis label to secondary y-axis in matplotlib

前端 未结 4 849
情深已故
情深已故 2020-11-27 10:04

I can add a y label to the left y-axis using plt.ylabel, but how can I add it to the secondary y-axis?

table = sql.read_frame(query,connection)
         


        
4条回答
  •  一向
    一向 (楼主)
    2020-11-27 10:40

    For everyone stumbling upon this post because pandas gets mentioned, you now have the very elegant and straighforward option of directly accessing the secondary_y axis in pandas with ax.right_ax

    So paraphrasing the example initially posted, you would write:

    table = sql.read_frame(query,connection)
    
    ax = table[[0, 1]].plot(ylim=(0,100), secondary_y=table[1])
    ax.set_ylabel('$')
    ax.right_ax.set_ylabel('Your second Y-Axis Label goes here!')
    

    (this is already mentioned in these posts as well: 1 2)

提交回复
热议问题