Location String := (best, upper right, upper left, lower left, lower right, right , center left, center right,lower center, upper center, center) bbox_to_anchor := BboxBase, 2-tuple (x, y) , or 4-tuple (x, y, width, height) of floats
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
x = np.linspace(0, 10, 1000)
y = (x-5) ** 2
y2 = 25-(x-5) **2
fig = plt.figure(figsize=(6, 4))
ax1 = fig.add_subplot(1,1,1)
ax1.plot(x, y, label = '(x-5)^2')
ax1.plot(x, y2, label = '-(x-5)^2 +25')
ax1.legend()
# Test center left
ax1.legend(loc='center left', bbox_to_anchor=(0.5, 0.5))
fig
# Test center
ax1.legend(loc='center', bbox_to_anchor=(0.5, 0.5))
fig
# Test center right
ax1.legend(loc='center right', bbox_to_anchor=(0.5, 0.5))
fig
# Test upper center
ax1.legend(loc='upper center', bbox_to_anchor=(0.5, 0.5))
fig
# Test upper center
ax1.legend(loc='upper right', bbox_to_anchor=(0.5, 0.5))
fig
# Test bbox_to_anchor
ax1.legend(loc='center', bbox_to_anchor=(0.5, 0.5))
fig
# Test bbox_to_anchor
ax1.legend(loc='center', bbox_to_anchor=(0.5, 0.5, 0.3, 0.3))
fig