There are many ways to put the legend out of the plot:-
But the most important thing you can do is use the bbox_to_anchor keyword argument to place the legend partially outside the axes and/or decrease the font size.
This keyword gives a great degree of control for manual legend placement. For example, if you want your axes legend located at the figure’s top right-hand corner instead of the axes’ corner, simply specify the corner’s location and the coordinate system of that location. Then you can use the following piece of code.
An example that illustrates how we use bbox_to_anchor to put the legend out of the plot:-
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = plt.subplot(111)
for i in xrange(5):
ax.plot(x, i * x, label='$y = %ix$' % i)