我有一個來自加速度計(x,y,z)的數據字符串(在文本文件」XXX XXX XXX「中看起來像這樣,我試圖讀取它並轉換爲帶有三個子圖的數據線圖我正在修改一些朋友的代碼來做這件事,但我不確定其中一些錯誤是從哪裏來的,很明顯是初學者程序員,非常感謝。錯誤:與基地無效字面INT()10對於基數爲10的int()無效:「
import os
import numpy as npy
import matplotlib.pyplot as plt
global y0,y1,y2
increment_size = 8000
datasample_size = 16000
from os.path import join
filepath = "C:\\Users\\Riley\\Documents\\Programming\\"
infile = join(filepath, 'data.txt')
infile = open(infile,"r")
singleline = infile.readline()
asciidata = singleline.split()
asciidata[0]=asciidata[0][3:]
y0=[int(asciidata[0])]
y1=[int(asciidata[1])]
y2=[int(asciidata[2])]
count = 0
for singleline in infile:
count += 1
if (count % 10000) == 0:
print(count)
asciidata = singleline.split()
y0.append(int(asciidata[0]))
y1.append(int(asciidata[1]))
y2.append(int(asciidata[2]))
infile.close()
totaldata=count-1
print(totaldata)
low = 0
high = datasample_size
while low < totaldata:
t = npy.arange(low,high)
plt.subplot(311)
plt.ylim(-2000,2000)
plt.plot(t,y0[low:high])
plt.subplot(312)
plt.ylim(-2000,2000)
plt.plot(t,y1[low:high])
plt.subplot(313)
plt.ylim(-2000,2000)
plt.plot(t,y2[low:high])
outfilename = filepath + 'Plots/' + shortfilename + '_' + str(low) + '.png'
plt.savefig(outfilename)
outfilename2 = filepath + 'Datasegments/' + shortfilename + '_' + str(low) + '.txt'
outfile = open(outfilename2,"w")
for j in range(low,high):
outfile.write(str(y0[j])+'\t'+str(y1[j])+'\t'+str(y2[j])+'\n')
# print(low),
plt.show()
low = low + increment_size
high = high + increment_size
if high > totaldata:
high = totaldata
# if low > 10000:
# break
# plt.close()