**
**
(1)设置图列位置
```python
plt.legend(loc=' ')
![](https://img-blog.csdnimg.cn/20200830165252486.png#pic_center)
**(2)设置图例字体大小**
```python
fontsize : int or float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}
(3)设置图例边框及背景
plt.legend(loc='best',frameon=False) #去掉图例边框
plt.legend(loc='best',edgecolor='blue') #设置图例边框颜色
plt.legend(loc='best',facecolor='blue') #设置图例背景颜色,若无边框,参数无效
对于边框还可以采用面向对象方式:
legend = plt.legend(["First", "Second"])
frame = legend.get_frame()
frame.set_facecolor('blue')
(4)设置图例标题
legend = plt.legend(["BJ", "SH"], title='Beijing VS Shanghai')
或者
plt.plot(["BJ", "SH"],loc='upper left',title='Beijing VS Shanghai')
(5)设置图例名字及对应关系
legend = plt.legend([p1, p2], ["BJ", "SH"])
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0,10,1)
plt.plot(x,x,'r--',x,np.cos(x),'g--',marker='*')
plt.xlabel('row')
plt.ylabel('cow')
plt.legend(["BJ","SH"],loc='upper left',loc='upper left')
plt.show()