How to put the legend out of the plot

后端 未结 17 3196
时光说笑
时光说笑 2020-11-21 04:42

I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, a

17条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 05:19

    Just call legend() call after the plot() call like this:

    # matplotlib
    plt.plot(...)
    plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    
    # Pandas
    df.myCol.plot().legend(loc='center left', bbox_to_anchor=(1, 0.5))
    

    Results would look something like this:

    enter image description here

提交回复
热议问题