import os import glob import pandas as pd import numpy as np import matplotlib import matplotlib.pyplot as plt import japanize_matplotlib as jpplt import math folderpath = os.getcwd() filepathes = glob.glob(folderpath + "/*.txt") print(filepathes) def near(step): a = [1,2,5,10] a_gap = [] for i in range(len(a)): a_gap.append(abs(step-a[i])) return a[a_gap.index(min(a_gap))] def grf_scope(data): max= data.max() min= data.min() step = abs(max-min)/5 print(round(math.log10(step))) step_e = [step/10**round(math.log10(step)),10**round(math.log10(step))] step_data = near(step_e[0])*step_e[1] lim_min = ((min//step_data)-1)*step_data lim_max = ((max//step_data)+1)*step_data return np.array([lim_min,lim_max]) def isEqual(x): return all(i == x[0] for i in x) grf_list = {'IGT':0 ,'X50':1, 'X10-X90':2, 'X10-X50':3, 'X50-X90':4, 'Qwork':5, 'Qexhaust':6, 'Qunburn':7, 'Qcool':8} grf_use = [2,3,4,5] grf_maker_list = ["o",",","v","*","^","1","2","3"] grf_color_list =["#000000","#ff0000","#0000ff","#008000","#4b0082","#8b4513","#00ced1","#ffa500"] datalists = [] for file_index, filepath in enumerate(filepathes): df = pd.read_csv(filepath,header=None) dataheader = np.array(df.iloc[0,:]) if file_index == 0: dataheaders = np.array([dataheader]) print(file_index,dataheaders) else: dataheaders = np.vstack([dataheaders,dataheader]) datalist = np.array(df.iloc[1:,:],dtype= float).T datalists.append(datalist) for grf_index in grf_use: plt.rcParams["font.size"] = 20 plt.rcParams['font.family'] = 'Times New Roman' fig = plt.figure(facecolor = (0,0,0,0)) ax = fig.add_subplot(111) ax.set_facecolor((0,0,0,0)) for data_index,datalist in enumerate(datalists): x_data = datalist[1] y_data = datalist[grf_index] x_grf_scp = grf_scope(x_data) y_grf_scp = grf_scope(y_data) print(x_grf_scp) print(y_grf_scp) plt.xlim(x_grf_scp[0],x_grf_scp[1]) plt.ylim(y_grf_scp[0],y_grf_scp[1]) plt.xlabel(dataheader[1]) plt.ylabel(dataheader[grf_index]) plt.scatter(x_data,y_data,marker=grf_maker_list[data_index],color = grf_color_list[data_index]) plt.plot(x_data,y_data,color = grf_color_list[data_index]) plt.tight_layout() plt.savefig(f"{folderpath}/{dataheader[grf_index]}_graph.png") plt.close()