You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FC_Single/_Python/csv2png.py

72 lines
2.2 KiB
Python

import pandas as pd
import matplotlib.pyplot as plt
import textwrap
from unicodedata import name
from matplotlib import rc
rc('font', family='Malgun Gothic')
def savePlot(*arg):
# def savePlot(arg):
file_path = arg[0]
targets = arg[1].split(',')
#find data set
with open(file_path) as fp:
state = 0
idxData = 0
datas = [pd.DataFrame({' ' : []})]
del datas[0]
for i, line in enumerate(fp):
if '#' in line[0] and state == 0:
state = 1
print(i, line)
if ('Time' in line) and (state == 1):
state = 2
skipRowsNum= i
if (line == '\n') and state == 2:
state = 0
nRowsNum = i - skipRowsNum
print(skipRowsNum, nRowsNum)
datas.append(pd.read_csv(file_path, engine='python', sep = '\t', skiprows=skipRowsNum, nrows = nRowsNum))
if state == 2:
state = 0
nRowsNum = i -skipRowsNum
print(skipRowsNum, nRowsNum)
datas.append(pd.read_csv(file_path, engine='python', sep = '\t', skiprows=skipRowsNum, nrows = nRowsNum))
idxData = 0
for data in datas:
names = list(data)
time = data[names[0]]
idxData += 1
for target in targets:
target = textwrap.dedent(target)
dt2plot = data[[]]
for name in names:
if target in name:
# print(name)
dt2plot = pd.concat([dt2plot,data[name]],axis=1)
plt.figure(figsize=(15,8))
plt.plot(time, dt2plot)
plt.grid()
x = list(dt2plot)
plt.legend(x,loc='best')
plt.title(target)
if len(datas)>1:
numData = '_' + str(idxData)
else:
numData = ''
plt.savefig(file_path + numData + '_' + target + '.png')
plt.clf()
# arg = ['C:/GIT/Logging Data/220921-164219_Log','[Flow],[Temp],[Pressure]']
# arg = ['C:/GIT/Logging Data/220922-085924_Log','[Flow],[Temp],[Pressure]']
# arg = ['C:/GIT/Logging Data/220921-164219_Log']
# savePlot(arg)