import matplotlib.pyplot as plt import pandas as pd import os dirs = r'.\predictions\OldDFU\FUSegNet_model_prediction\\' # model prediction directory loc = dirs + "result_boxplot.xlsx" # excel file generated by eval_boxplot.py exl = [pd.read_excel(loc, sheet_name="cat-0"), pd.read_excel(loc, sheet_name="cat-1"), pd.read_excel(loc, sheet_name="cat-2"), pd.read_excel(loc, sheet_name="cat-3"), pd.read_excel(loc, sheet_name="cat-4"), pd.read_excel(loc, sheet_name="cat-5"), pd.read_excel(loc, sheet_name="cat-6"), pd.read_excel(loc, sheet_name="cat-7"), pd.read_excel(loc, sheet_name="cat-8"), pd.read_excel(loc, sheet_name="cat-9"), ] titles = ['Category-1', 'Category-2', 'Category-3', 'Category-4', 'Category-5', 'Category-6', 'Category-7', 'Category-8', 'Category-9', 'Category-10',] assert len(titles)==len(exl), 'Only positive numbers are allowed' save = True if save: save_loc = dirs + "boxplot" if not os.path.exists(save_loc): os.makedirs(save_loc) fig, ax = plt.subplots(2,5, figsize=(16,5)) for cnt, i in enumerate(range(len(exl))): data = [exl[i]["iou"], exl[i]["Precision"], exl[i]["Recall"], exl[i]["Dice"]] # plot. Set color of marker edge flierprops = dict(marker='o', markerfacecolor='r', markersize=5, linestyle='none', markeredgecolor='g') # Create index for ax[][] if cnt < len(exl)//2: j = 0 # for 1st row, j = 0 else: j = 1 # for 2nd row, j = 1 # bp = ax[j][i%5].boxplot(data, whis=[5, 95], showmeans=True, showfliers=True, flierprops=flierprops) bp = ax[j][i%5].boxplot(data, whis=1.5, showmeans=True, showfliers=True, flierprops=flierprops) # Get a list of Line2D objects, representing a single line from the # minimum to the maximum flier points. fliers = bp['fliers'] 'Uncomment to keep the outmost outliers' # # Iterate over it. Keep one flier only. # for fly in fliers: # fdata = fly.get_data() # print(fdata) # if fdata[0].shape[0] >= 2: # Ensuring a 2 x 2 array # fly.set_data([fdata[0][0],fdata[0][-1]],[fdata[1][0],fdata[1][-1]]) ax[j][i%5].set_title(titles[i], fontsize=10) ax[j][i%5].set_xticks([1, 2, 3, 4], ['IoU', 'P', 'R', 'DSC']) fig.tight_layout() fig.subplots_adjust(wspace=0.2, hspace=0.3) if save: fig.savefig(os.path.join(save_loc, "boxplot.png"))