How to put the legend out of the plot

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

    Not exactly what you asked for, but I found it's an alternative for the same problem. Make the legend semi-transparant, like so: matplotlib plot with semi transparent legend and semitransparent text box

    Do this with:

    fig = pylab.figure()
    ax = fig.add_subplot(111)
    ax.plot(x,y,label=label,color=color)
    # Make the legend transparent:
    ax.legend(loc=2,fontsize=10,fancybox=True).get_frame().set_alpha(0.5)
    # Make a transparent text box
    ax.text(0.02,0.02,yourstring, verticalalignment='bottom',
                         horizontalalignment='left',
                         fontsize=10,
                         bbox={'facecolor':'white', 'alpha':0.6, 'pad':10},
                         transform=self.ax.transAxes)
    

提交回复
热议问题