代码:
1 # -*- coding: utf-8 -*- 2 """ 3 Created on Thu Jul 12 16:37:47 2018 4 5 @author: zhen 6 """ 7 """ 8 正弦和余弦图 9 """10 import matplotlib.pyplot as plt11 12 import numpy as np13 14 x = np.linspace(-np.pi, np.pi, 256, endpoint=True)15 16 y_cos = np.cos(x)17 y_sin = np.sin(x)18 19 plt.plot(x, y_cos)20 plt.plot(x, y_sin)21 22 title("Function $\sin$ and $\cos$")23 24 xlim(-3.6, 3.6)25 ylim(-1.0, 1.0)26 27 # format ticks at specific values28 xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],[r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+pi/2$', r'$+\pi$'])29 yticks([-1, 0, +1],[r'$-1$', r'$0$', r'$+1$'])30 31 plt.show()
结果: