python读取文本绘制动态速度曲线
本文实例为大家分享了python读取文本绘制动态速度曲线的具体代码,供大家参考,具体内容如下
由于需要分析机械加工过程中各个轴的速度,于是用软件导出了数据,写了这个python脚本来显示速度曲线。
效果图如下:
源代码:
import numpy as np from matplotlib import pyplot as plt from matplotlib import animation path = "Nccut_TraceFile.log" file = open(path, 'r') AMat = []; BMat = [];XMat = [];YMat = [];ZMat = []; for line in file.readlines(): lineArr = line.strip().split() AMat.append(int(lineArr[0])) BMat.append(int(lineArr[1])) XMat.append(int(lineArr[2])) YMat.append(int(lineArr[3])) ZMat.append(int(lineArr[4])) fig = plt.figure() axA = fig.add_subplot(5,1,1,xlim=(0, 0.2), ylim=(0, 40)) axB = fig.add_subplot(5,1,2,xlim=(0, 0.2), ylim=(0, 40)) axX = fig.add_subplot(5,1,3,xlim=(0, 0.2), ylim=(0, 200)) axY = fig.add_subplot(5,1,4,xlim=(0, 0.2), ylim=(0, 200)) axZ = fig.add_subplot(5,1,5,xlim=(0, 0.2), ylim=(0, 200)) lineA, = axA.plot([], [], lw=1) lineB, = axB.plot([], [], lw=1) lineX, = axX.plot([], [], lw=1) lineY, = axY.plot([], [], lw=1) lineZ, = axZ.plot([], [], lw=1) def init(): lineA.set_data([], []) lineB.set_data([], []) lineX.set_data([], []) lineY.set_data([], []) lineZ.set_data([], []) return lineA,lineB,lineX,lineY,lineZ def animate(i): t = np.linspace(0, 0.2, 10) yA = AMat[i:10 + i] lineA.set_data(t, yA) yB = BMat[i:10 + i] lineB.set_data(t, yB) yX = XMat[i:10 + i] lineX.set_data(t, yX) yY = YMat[i:10 + i] lineY.set_data(t, yY) yZ = ZMat[i:10 + i] lineZ.set_data(t, yZ) return lineA,lineB,lineX,lineY,lineZ anim1=animation.FuncAnimation(fig, animate, init_func=init, frames=len(XMat)-10, interval=2) plt.show()
读取的文本格式如下:
相关推荐
wordmhg 2020-11-06
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20