1. dialog로부터 파일 경로 받아오기
###########################################################
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
print('파일경로:', file_path)
###########################################################
2. 경로에서 데이터 불러오기
###########################################################
import numpy as np
import matplotlib.pyplot as plt
file = open(file_path, 'r', encoding = 'utf-8')
f = file.read()
file.close() # 인터넷보면 닫아야된다는 주장도 있고 아닌 주장도 있고.....
channel_names = f[int(f.find('[column names]')+len('[column names]\n')):int(f.find('[data]'))-2]
# column names에 있는 체널만 따오기 위해서 잘라냄
channel_names = channel_names.split(' ')
# split으로 나누어서 list 만들어 나중에 time, velocity와 같은 channel에 넣기위해 list로 만듬
###########################################################
3. 데이터 플롯하기
###########################################################
data = f[(int(f.find('[data]')))+len('[data]\n'):]
f = open('data.txt', 'w')
f.write(data)
f.close()
# 현재 데이터를 바로 긁어와서 구분하는 방법을 몰라서 txt로 만든다음 불러서 다시 데이터 나눔
data = np.loadtxt('data.txt')
time = data[:, channel_names.index('time')]
velocity = data[:, channel_names.index('velocity')]
plt.plot(time, velocity)
plt.show()
###########################################################
4. 결과
6. 전체 코딩
######### dialog로부터 선택된 파일경로 받아오기 #############
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
print('파일경로:', file_path)
###########################################################
import numpy as np
import matplotlib.pyplot as plt
file = open(file_path, 'r', encoding = 'utf-8')
f = file.read()
file.close() # 인터넷보면 닫아야된다는 주장도 있고 아닌 주장도 있고.....
channel_names = f[int(f.find('[column names]')+len('[column names]\n')):int(f.find('[data]'))-2]
# vbo파일에 column names에 있는 체널만 따오기 위해서 잘라냄
channel_names = channel_names.split(' ')
# split으로 나누어서 list 만들어 나중에 time, velocity와 같은 channel에 넣기위해 list로 만듬
data = f[(int(f.find('[data]')))+len('[data]\n'):]
f = open('data.txt', 'w')
f.write(data)
f.close()
# 현재 데이터를 바로 긁어와서 구분하는 방법을 몰라서 txt로 만든다음 불러서 다시 데이터 나눔
data = np.loadtxt('data.txt')
time = data[:, channel_names.index('time')]
velocity = data[:, channel_names.index('velocity')]
plt.plot(time, velocity)
plt.show()
'파이썬' 카테고리의 다른 글
pandas read_html() ValueError : No tables found 오류 (0) | 2021.08.17 |
---|---|
웹스크래핑 BeautifulSoup 설치와 에러발생 대처 방법 : bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library? (0) | 2021.08.14 |
기타 정보 모음 (0) | 2021.07.11 |
Jupyter - Anaconda 가상환경 (0) | 2021.07.07 |
Font : SourceHanSansk 설치 (0) | 2021.07.06 |