#绘制正弦、余弦曲线并添加辅助元素
(I)
#导入模块
import matplotlib.pyplot as plt
import numpy as np
#设置中文
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
#创建对象
fig = plt.figure()
ax = fig.add_subplot(111)
#绘制正弦、余弦曲线
x = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y1, y2 = np.sin(x), np.cos(x)
ax.plot(x, y1, x, y2)
#展示
plt.show()
#设置坐标轴的标签{在代码(I)中加入以下代码}
ax.set_xlabel("x轴")
ax.set_ylabel("y轴")
#设置x轴的刻度范围和刻度标签
ax.set_xlim(x.min()*1.5, x.max()*1.5)
ax.set_xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.p