import os import glob import pandas as pd import numpy as np import matplotlib import matplotlib.pyplot as plt import japanize_matplotlib as jpplt folderpath = os.getcwd() filepathes = glob.glob(folderpath + "/*.txt") print(filepathes) def grf_scope(x_data,y_data): xmax= x_data.max() xmin= x_data.min() ymax= y_data.max() ymin= y_data.min() x_lim_min = xmin - (xmax-xmin)*0.1 x_lim_max = xmax + (xmax-xmin)*0.1 y_lim_min = ymin - (ymax-ymin)*0.1 y_lim_max = ymax + (ymax-ymin)*0.1 return np.array([x_lim_min,x_lim_max,y_lim_min,y_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) print(df) 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] grf_scp = grf_scope(x_data,y_data) plt.xlim(grf_scp[0],grf_scp[1]) plt.ylim(grf_scp[2],grf_scp[3]) 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()