将图例绘制与外部
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(10)
y=x**2
fig= plt.figure()
ax =plt.subplot(111)
ax.plot(x,x,label='$y=x$')
ax.plot(x,y,label='$y=x^2$')
box=ax.get_position()
ax.set_position([box.x0,box.y0,box.width*0.8,box.height])
ax.legend(loc='upper left',bbox_to_anchor=(1.0,0.5))
plt.show()