| import matplotlib.pyplot as plt |
| import pandas as pd |
| import os |
|
|
| dirs = r'.\predictions\OldDFU\FUSegNet_model_prediction\\' |
|
|
| loc = dirs + "result_boxplot.xlsx" |
|
|
| 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"]] |
| |
| |
| flierprops = dict(marker='o', markerfacecolor='r', markersize=5, |
| linestyle='none', markeredgecolor='g') |
| |
| |
| if cnt < len(exl)//2: j = 0 |
| else: j = 1 |
|
|
| |
| bp = ax[j][i%5].boxplot(data, whis=1.5, showmeans=True, showfliers=True, flierprops=flierprops) |
| |
| |
| |
| fliers = bp['fliers'] |
| |
| 'Uncomment to keep the outmost outliers' |
| |
| |
| |
| |
| |
| |
| |
| 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")) |
| |
|
|
|
|
|
|