import numpy as np import matplotlib.pyplot as plt x = np.linspace(-np.pi, np.pi, 1000) cosy = np.cos(x) siny = np.sin(x) plt.xlim(min(x), max(x)) plt.ylim(min(cosy), max(cosy)+0.5) plt.plot(x, cosy) plt.plot(x, siny) # 设置坐标刻度 plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi *3/4, np.pi],) # 设置坐标轴 ax = plt.gca() ax.spines['left'].set_position(('data', 0)) ax.spines['bottom'].set_position(('data', 0)) ax.spines['right'].set_position(('data', 0)) ax.spines['top'].set_position(('data', 0)) plt.show()