绘制函数 y = f ( x ) = x 3 − 1 x y = f(x) = x^3 - \frac{1}{x} y=f(x)=x3−x1和其在 x = 1 x = 1 x=1处切线的图像
from matplotlib import pyplot as plt
def f(x):
return x**3-1/x
x = np.arange(0, 3, 0.1)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.plot(x, f(x),"-")
plt.plot(x, 4 * x - 4,"--")
plt.legend(['f(x)', 'Tangent line (x=1)'])
plt.show()