from matplotlib import pyplot as plt import numpy as np '''numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) retstep=True, return (samples, step), where step is the spacing between samples.''' x = np.linspace(-np.pi, np.pi, 256, endpoint=True) y = np.cos(x) y1 = np.sin(x) plt.plot(x, y) plt.plot(x, y1) # 设置图片标题 plt.title("Function $\cos$ and $\sin$") # 设置x轴和y轴坐标限制 plt.xlim(-3.0, 3.0) plt.ylim(-1.0, 1.0) # 设置坐标标签 plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi], [r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$']) plt.yticks([-1, 0, 1], [r'$-1$', r'$0$', r'$+1$']) plt.show()