How to specify legend position in matplotlib in graph coordinates

前端 未结 4 1611
梦如初夏
梦如初夏 2020-11-29 06:52

I am aware of the bbox_to_anchor keyword and this thread, which very helpfully suggests how to manually place the legend:

How to put the legend out of the plot

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 07:55

    In addition to @ImportanceOfBeingErnest's post, I use the following line to add a legend at an absolute position in a plot.

    plt.legend(bbox_to_anchor=(1.0,1.0),\
        bbox_transform=plt.gcf().transFigure)
    

    For unknown reasons, bbox_transform=fig.transFigure does not work with me.

提交回复
热议问题