{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 97916 characters]",
      "text/plain": [
       "<Figure size 1200x700 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.patches as mpatches\n",
    "\n",
    "folds = ['Fold 1', 'Fold 2', 'Fold 3', 'Fold 4', 'Fold 5']\n",
    "only_desc = [0.9531471841, 0.9102803738, 0.9613453815, 0.9609895338, 0.8950984883]\n",
    "plus_u = [0.9545669664, 0.9166261682, 0.9769076305, 0.9722131304, 0.9098859368]\n",
    "plus_u_n = [0.9659252248, 0.9168224299, 0.968875502, 0.9814462417, 0.9180027485]\n",
    "plus_u_m_m = [0.9602460956, 0.9182242991, 0.96937751, 0.9724072312, 0.8973889143]\n",
    "plus_u_sel_n = [0.9645054425, 0.9168224299, 0.9789156627, 0.973358706, 0.952817224]\n",
    "\n",
    "data = np.array([only_desc, plus_u, plus_u_n, plus_u_m_m, plus_u_sel_n]) * 100\n",
    "max_indices = np.argmax(data, axis=0)\n",
    "\n",
    "x = np.arange(len(folds))\n",
    "width = 0.15\n",
    "\n",
    "colors = plt.cm.Spectral(np.linspace(0, 1, 5))\n",
    "fig, ax = plt.subplots(figsize=(12, 7))\n",
    "\n",
    "rects1 = ax.bar(x - 2 * width, data[0], width, label='Only Desc.', color=colors[0], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[0] == 0 else '')\n",
    "rects2 = ax.bar(x - width, data[1], width, label='+U.', color=colors[1], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[1] == 1 else '')\n",
    "rects3 = ax.bar(x, data[2], width, label='+U./N.', color=colors[2], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[2] == 2 else '')\n",
    "rects4 = ax.bar(x + width, data[3], width, label='+U./M.M.', color=colors[3], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[3] == 3 else '')\n",
    "rects5 = ax.bar(x + 2 * width, data[4], width, label='+U./Sel N.', color=colors[4], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[4] == 4 else '')\n",
    "\n",
    "for i in range(len(folds)):\n",
    "    ax.bar(x[i] - 2 * width, data[0][i], width, color=colors[0], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 0 else '')\n",
    "    ax.bar(x[i] - width, data[1][i], width, color=colors[1], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 1 else '')\n",
    "    ax.bar(x[i], data[2][i], width, color=colors[2], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 2 else '')\n",
    "    ax.bar(x[i] + width, data[3][i], width, color=colors[3], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 3 else '')\n",
    "    ax.bar(x[i] + 2 * width, data[4][i], width, color=colors[4], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 4 else '')\n",
    "\n",
    "desc_mean = np.mean(only_desc) * 100\n",
    "plus_u_mean = np.mean(plus_u) * 100\n",
    "plus_u_n_mean = np.mean(plus_u_n) * 100\n",
    "plus_u_m_m_mean = np.mean(plus_u_m_m) * 100\n",
    "sel_n_mean = np.mean(plus_u_sel_n) * 100\n",
    "\n",
    "ax.axhline(y=desc_mean, color=colors[0], linestyle='--')\n",
    "ax.axhline(y=plus_u_mean, color=colors[1], linestyle='--')\n",
    "ax.axhline(y=plus_u_n_mean, color=colors[2], linestyle='--')\n",
    "ax.axhline(y=plus_u_m_m_mean, color=colors[3], linestyle='--')\n",
    "ax.axhline(y=sel_n_mean, color=colors[4], linestyle='--', label='Sel N. Mean')\n",
    "\n",
    "ax.text(x[1], sel_n_mean + 0.5, f'Max: {sel_n_mean:.2f}%', ha='center', fontsize=20, color='black')\n",
    "ax.set_ylim([88, 100])\n",
    "\n",
    "ax.set_xticks(x)\n",
    "ax.set_xticklabels(folds, fontsize=20)\n",
    "\n",
    "ax.grid(True, which='both', linestyle='--', linewidth=0.7, alpha=0.7, zorder=1)\n",
    "\n",
    "ax.tick_params(axis='both', which='major', labelsize=20)\n",
    "\n",
    "hatch_patch = mpatches.Patch(facecolor='white', edgecolor='black', hatch='//', label='BEST')\n",
    "\n",
    "legend = ax.legend(handles=[hatch_patch] + ax.get_legend_handles_labels()[0], fontsize=20)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 111748 characters]",
      "text/plain": [
       "<Figure size 1200x700 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.patches as mpatches\n",
    "\n",
    "# Fold 및 실험 데이터\n",
    "folds = ['Fold 1', 'Fold 2', 'Fold 3', 'Fold 4', 'Fold 5']\n",
    "t5_tiny = [0.9479413157, 0.9028037383, 0.9708835341, 0.9652711703, 0.9496106276]\n",
    "t5_mini = [0.957406531, 0.9130841121, 0.9764056225, 0.9686013321, 0.9459459459]\n",
    "t5_small = [0.9588263133, 0.9196261682, 0.9748995984, 0.9738344434, 0.9454878607]\n",
    "bart_base = [0.9597728348, 0.9126168224, 0.9723895582, 0.9714557564, 0.9601465873]\n",
    "t5_base = [0.9645054425, 0.9168224299, 0.9789156627, 0.973358706, 0.952817224]\n",
    "\n",
    "\n",
    "# 데이터 준비\n",
    "data = np.array([t5_tiny, t5_mini, t5_small, bart_base, t5_base]) * 100\n",
    "max_indices = np.argmax(data, axis=0)\n",
    "\n",
    "# x축 설정\n",
    "x = np.arange(len(folds))\n",
    "width = 0.15\n",
    "\n",
    "# 색상 설정\n",
    "colors = plt.cm.Spectral(np.linspace(0, 1, 5))\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(12, 7))\n",
    "\n",
    "# 바 차트 그리기\n",
    "rects1 = ax.bar(x - 2 * width, data[0], width, label='T5-Tiny', color=colors[0], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[0] == 0 else '')\n",
    "rects2 = ax.bar(x - width, data[1], width, label='T5-Mini', color=colors[1], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[1] == 1 else '')\n",
    "rects3 = ax.bar(x, data[2], width, label='T5-Small', color=colors[2], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[2] == 2 else '')\n",
    "rects4 = ax.bar(x + width, data[3], width, label='BART-Base', color=colors[3], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[3] == 3 else '')\n",
    "rects5 = ax.bar(x + 2 * width, data[4], width, label='T5-Base', color=colors[4], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[4] == 4 else '')\n",
    "\n",
    "for i in range(len(folds)):\n",
    "    ax.bar(x[i] - 2 * width, data[0][i], width, color=colors[0], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 0 else '')\n",
    "    ax.bar(x[i] - width, data[1][i], width, color=colors[1], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 1 else '')\n",
    "    ax.bar(x[i], data[2][i], width, color=colors[2], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 2 else '')\n",
    "    ax.bar(x[i] + width, data[3][i], width, color=colors[3], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 3 else '')\n",
    "    ax.bar(x[i] + 2 * width, data[4][i], width, color=colors[4], edgecolor='black', linewidth=1.5, zorder=3, hatch='//' if max_indices[i] == 4 else '')\n",
    "\n",
    "# 각 모델의 평균 계산\n",
    "t5_tiny_mean = np.mean(t5_tiny) * 100\n",
    "t5_mini_mean = np.mean(t5_mini) * 100\n",
    "t5_small_mean = np.mean(t5_small) * 100\n",
    "bart_base_mean = np.mean(bart_base) * 100\n",
    "t5_base_mean = np.mean(t5_base) * 100\n",
    "\n",
    "# 평균을 점선으로 추가\n",
    "ax.axhline(y=t5_tiny_mean, color=colors[0], linestyle='--', label='T5-Tiny Mean')\n",
    "ax.axhline(y=t5_mini_mean, color=colors[1], linestyle='--')\n",
    "ax.axhline(y=t5_small_mean, color=colors[2], linestyle='--')\n",
    "ax.axhline(y=bart_base_mean, color=colors[3], linestyle='--')\n",
    "ax.axhline(y=t5_base_mean, color=colors[4], linestyle='--', label='T5-Base Mean')\n",
    "\n",
    "# 가장 높은 평균값과 가장 낮은 평균값 계산\n",
    "max_mean = max(t5_tiny_mean, t5_mini_mean, t5_small_mean, bart_base_mean, t5_base_mean)\n",
    "min_mean = min(t5_tiny_mean, t5_mini_mean, t5_small_mean, bart_base_mean, t5_base_mean)\n",
    "\n",
    "# Fold 2의 중앙 정렬로 Max와 Min 텍스트 추가\n",
    "ax.text(x[1], max_mean + 0.5, f'Max: {max_mean:.2f}%', ha='center', fontsize=20, color='black')\n",
    "ax.text(x[1], min_mean - 0.8, f'Min: {min_mean:.2f}%', ha='center', fontsize=20, color='black')\n",
    "\n",
    "# y축 설정\n",
    "ax.set_ylim([88, 100])\n",
    "\n",
    "ax.set_xticks(x)\n",
    "ax.set_xticklabels(folds, fontsize=20)\n",
    "\n",
    "ax.grid(True, which='both', linestyle='--', linewidth=0.7, alpha=0.7, zorder=1)\n",
    "\n",
    "ax.tick_params(axis='both', which='major', labelsize=20)\n",
    "\n",
    "hatch_patch = mpatches.Patch(facecolor='white', edgecolor='black', hatch='//', label='BEST')\n",
    "legend = ax.legend(handles=[hatch_patch] + ax.get_legend_handles_labels()[0], fontsize=20, loc='upper right')\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
