**
Matplotlib学习笔记——添加图例
**
import matplotlib.pyplot as plt
import numpy as np
import math
x = np.linspace(-2*math.pi, 2*math.pi, 100)
y1 = 3 * np.sin(x)
y2 = x**2 + 1
plt.figure()
plt.plot(x, y1, label='sin(x)') # label='图例信息'
plt.plot(x, y2, color='red', linewidth=5.0, linestyle='--', label='x^2+1')
plt.legend() # 显示图例
plt.show()