展开全部
1, 导入matplotlib.pyplot, numpy 包:2113
import numpy as np
import matplotlib.pyplot as plt
2,添加主题样式:
plt.style.use('mystyle')
3, 设置图的大5261小,添加子图:4102
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
4,绘制1653sin, cos:
x = np.arange(-np.pi, np.pi, np.pi / 100)
y1 = np.sin(x)
y2 = np.cos(x)
sin, = ax.plot(x, y1, color='red', label='sin')
cos, = ax.plot(x, y2, color='blue', label='cos')
ax.set_ylim([-1.2, 1.2])
第二种方式 拆分显示
sin_legend = ax.legend(handles=[sin], loc='upper right')
ax.add_artist(sin_legend)
ax.l