How to specify legend position in matplotlib in graph coordinates

前端 未结 4 1603
梦如初夏
梦如初夏 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:36

    According to the matplotlib legend documentation:

    The location can also be a 2-tuple giving the coordinates of the lower-left corner of the legend in axes coordinates (in which case bbox_to_anchor will be ignored).

    Thus, one could use:

    plt.legend(loc=(x, y))
    

    to set the legend's lower left corner to the specified (x, y) position.

提交回复
热议问题