本文实例为大家分享了python读取文本绘制动态速度曲线的具体代码,供大家参考,具体内容如下
由于需要分析机械加工过程中各个轴的速度,于是用软件导出了数据,写了这个python脚本来显示速度曲线。
效果图如下:
源代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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()
|
读取的文本格式如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/Galileo2017/article/details/77503789