How to put the legend out of the plot

后端 未结 17 3156
时光说笑
时光说笑 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:27

    don't know if you already sorted out your issue...probably yes, but... I simply used the string 'outside' for the location, like in matlab. I imported pylab from matplotlib. see the code as follow:

    from matplotlib as plt
    from matplotlib.font_manager import FontProperties
    t = A[:,0]
    sensors = A[:,index_lst]
    
    for i in range(sensors.shape[1]):
        plt.plot(t,sensors[:,i])
    
    plt.xlabel('s')
    plt.ylabel('°C')
    lgd = plt.legend(loc='center left', bbox_to_anchor=(1, 0.5),fancybox = True, shadow = True)
    

提交回复
热议问题