fig = pyplot.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
ax.set_position([0.1, 0.1, 0.5, 0.8])
ax.plot(x, y)
leg = ax.legend(['abc'], loc='center left', bbox_to_anchor=(1.0, 0.5))
fig.savefig('aaa.png')
Matplotlib savefig with a legend outside the plot