1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import glob
- import os
- import pandas as pd
- import matplotlib.pyplot as plt
- import time
- import numpy as np
- import seaborn as sns
- path = os.getcwd()
- def draw(filename):
- conditions = file['condition']
- result = file[filename]
- plt.figure(figsize=(9, 6), dpi=100)
- plt.bar(conditions, result, width=0.35, color=colors,alpha=a)
- plt.title(filename)
- plt.ylabel('score')
- plt.grid(alpha=0, linestyle=':')
- plt.savefig(filename + ".jpg", dpi=300)
- #plt.show()
- def drawTogether():
- plt.figure(figsize=(20,7))
- x = np.arange(len(scales))
- total_width, n = 0.8, 4
- width = total_width / n
-
- for i in range(0,4):
- result = []
- for scale in scales:
- result.append(file.iloc[i][scale])
- plt.bar(x+width*(i-1),result,width=width,color=colors[i],label=file.iloc[i]["condition"],alpha=a)
- plt.legend()
-
- plt.xticks(x+width/2,scales)
- #plt.show()
-
- plt.savefig("summary.jpg",dpi=300)
- # Merge all the .csv file
- all_files = glob.glob(os.path.join(path, "*.csv"))
- df_from_each_file = (pd.read_csv(f, sep=',') for f in all_files)
- df_merged = pd.concat(df_from_each_file, ignore_index=True)
- # Save the file to Merged.csv in the same folder
- df_merged.to_csv( "Merged.csv")
- # save the results in csv
- file = df_merged.groupby(["condition"]).mean()
- file.to_csv( "Mean.csv")
- file = pd.read_csv("Mean.csv")
- scales = ["Collision","Drive Distance","Total driving time","Adverage speed","Rescued Target", "Remained Visible Target","Remained Unvisible Target"]
- colors = sns.color_palette()
- a = 0.6
- for scale in scales:
- draw(scale)
- drawTogether()
|