python 使用matplotlib 绘制cos函数图像带有辅助线。为什么只出来cos图像没有辅助线呢?语句在下方请帮我解答
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.05,10,1000)
y = np.cos(x)
plt.plot(x,y,ls="-",lw=2,label="plot figure")
plt.legend()
plt.show()
plt.xlim(0,10)
plt.ylim(-1.3,1.3)
plt.xlabel("x")
plt.ylabel("y")
plt.grid(axis="y")
plt.show()
plt.grid(linestyle=":",color="r")
plt.axhline(y=0.0,c="r",ls="--",lw=2)
plt.axvline(x=5.0,c="r",ls="--",lw=2)
plt.axvspan(xmin=4.0,xmax=6.0,facecolor="y",alpha=0.3)
plt.axhspan(ymin=-0.3,ymax=0.3,facecolor="y",alpha=0.3)
plt.annotate("maximum",xy=(0,1.0),xytext=((np.pi/2)+0.15,1.5),weight="bold",color="b",arrowprops=dict(arrowstyle="->",connectionstyle="arc3",color="b"))
plt.text(2,0,"y=cos(x)",weight="bold",color="b")
plt.title("y=cos(x)")
例图是这样的: