python讀取文字繪製動態速度曲線

2022-10-04 09:03:07 字數 1911 閱讀 3952

由於需要分析機械加工過程中各個軸的速度,於是用軟體匯出了資料,寫了這個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 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(raxxkurwf, )

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()

讀取的文字格式如下:

本文標題: python讀取文字繪製動態速度曲線

本文位址:

python繪製動態曲線教程

從txt種獲取資料 並且通過動態曲線顯示 import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import time fixing random state for r...

Python學習之繪製動態時鐘

移動到指定位置 def skip step penup forward step pendown 畫指標 def drawpointer name,length reset skip length 0.1 begin poly forward length 1.1 end poly handform...

Python Turtle繪製動態時鐘

coding utf 8 import turtle from datetime import 抬起畫筆,向前運動一段距離放下 def skip step turtle.penup turtle.forward step turtle.pendown def mkhand name,length 註...