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.
Note that the x
and y
coordinates here are relative, meaning that x=0
is the left most point in the plot and x=1
is the rightmost point in the plot. Similarly for y=0
and y=1
along the height of the plot, where y=0
is the bottom, and y=1
is the top.