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

In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
import numpy as np
In [6]:
x = np.linspace(0, 10, 1000)
y = (x-5) ** 2
y2 = 25-(x-5) **2
In [9]:
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()
Out[9]:
<matplotlib.legend.Legend at 0x1df41d29308>
In [11]:
# Test center left
ax1.legend(loc='center left', bbox_to_anchor=(0.5, 0.5))
fig
Out[11]:
In [13]:
# Test center
ax1.legend(loc='center', bbox_to_anchor=(0.5, 0.5))
fig
Out[13]:
In [15]:
# Test center right
ax1.legend(loc='center right', bbox_to_anchor=(0.5, 0.5))
fig
Out[15]:
In [18]:
# Test upper center
ax1.legend(loc='upper center', bbox_to_anchor=(0.5, 0.5))
fig
Out[18]:
In [19]:
# Test upper center
ax1.legend(loc='upper right', bbox_to_anchor=(0.5, 0.5))
fig
Out[19]:
In [24]:
# Test bbox_to_anchor
ax1.legend(loc='center', bbox_to_anchor=(0.5, 0.5))
fig
Out[24]:
In [29]:
# Test bbox_to_anchor
ax1.legend(loc='center', bbox_to_anchor=(0.5, 0.5, 0.3, 0.3))
fig
Out[29]:
In [ ]: