在曲线某一点做切线
x = np.arange(0,10,0.1) def line1(x): return np.sin(x)*2 def slope(x): h = 1e-4 k = (line1(x+h)-line1(x-h))/(2*h) b = line1(x)-k*x return k,b # 通过计算导数的方法得到x点的斜率k,再计算在x点的截距b y = line1(x) plt.plot(x,y) k,b = slope(4) x_slope = k*x +b plt.plot(x,x_slope) plt.ylim(-3,3) plt.show()