绘制cos和sin图表

import numpy as np 
import matplotlib.pyplot as plt
x = np.linspace(-np.pi,np.pi,64,endpoint = True)
c , s = np.cos(x) , np.sin(x)
plt.figure(1)
plt.plot(x,c,color = 'red',linewidth = 1.0,linestyle = '-',label='cos',alpha=0.5)
plt.plot(x,s,'b*',label = 'sin')#不知道为什么没有label
plt.title('cos&sin')

ax = plt.gca()#轴的编辑器
ax.spines["right"].set_color("none")#隐藏右边上上边的线
ax.spines["top"].set_color("none")
ax.spines["left"].set_position(("data",0))#这里有两层括号
ax.spines["bottom"].set_position(("data",0))
#中间这段实在搞不清楚
"""
ax.xaxis.set_ticks_position("bottom")
ax.yaxis.set_ticks_positon("left")
#plt.xticks([],[])

plt.legent(loc = "upper left")
"""
plt.grid()#加网格线
plt.legend(['cos','sin'])#加图例
t=1
plt.plot([t,t],[0,np.cos(t)],"y")#画线
plt.annotate("cos(1)",xy=(t,np.cos(1)),xycoords="data",xytext=(+10,+30),
             textcoords="offset points",
             arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.2"))
             #这段也用了好长时间,加指点
plt.show()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43139613/article/details/82791339