python绘制动态曲线教程
从txt种获取数据并且通过动态曲线显示
importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotlib.animationasanimation
importtime
#Fixingrandomstateforreproducibility
np.random.seed(196)
path="feed.txt"
file=open(path,'r')
data=[]
forlineinfile.readlines():
lineArr=line.strip().split()
data.append(int(lineArr[0]))
xdata=np.arange(0,len(data))
#初始数据绘图
dis=np.zeros(40)
dis2=dis
fig,ax=plt.subplots()
line,=ax.plot(dis)
ax.set_ylim(0,100)
plt.grid(True)
ax.set_ylabel("distance:m")
ax.set_xlabel("time")
defupdate(frame):
globaldis
globaldis2
globalline
#读入模拟
a=frame
time.sleep(np.random.rand()/10)
#绘图数据生成
dis[0:-1]=dis2[1:]
dis[-1]=a
dis2=dis
#绘图
line.set_ydata(dis)
#颜色设置
plt.setp(line,'color','b','linewidth',2.0)
returnline
ani=animation.FuncAnimation(fig,update,frames=data,interval=10)
plt.show()
输出:
补充拓展:Python绘制mes曲线实例
mes曲线:累计误差曲线。一般用于测试生成的关键点与标定的关键点间的差异情况,差异一般是指两点间的欧氏距离。
标记点坐标p_g(x,y)
预测点坐标p_t(x,y)
dist(p_g,p_t)可以计算两点间的欧氏距离。
defdist(point1,point2): return((point1[0]-point2[0])**2+(point1[1]-point2[1])**2)**0.5
在人脸的关键点检测中,dist()计算的距离/双眼间距离进行归一化。将归一化后的值append到MSE,调用drawCDFSingle(MSE)即可看到累计误差曲线。
defdrawCDFSingle(MSE):
plotDataset=[[],[]]
plt.grid()
plt.xlabel("pixelerror")
plt.ylabel("Fractionofnumberoflandmarks")
plt.title('CDF')
foriinrange(len(MSE[0])):
sumnum=0
mse_point=[x[i]forxinMSE]
mse_point.sort()
plotDataset[0]=[]
plotDataset[1]=[]
fortinrange(len(mse_point)):
plotDataset[0].append(float(t+1)/len(mse_point))
#sumnum=sumnum+float(mse_point[t])
plotDataset[1].append(float(mse_point[t]))
plt.plot(plotDataset[1],plotDataset[0],color[i%len(color)]+linestyle[i%len(linestyle)],linewidth=2,label=i)
plt.legend()#makelegend
plt.show()
以上这篇python绘制动态曲线教程就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。