{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python packages used in this code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "import pickle\n",
    "import sklearn\n",
    "import platform\n",
    "import sys\n",
    "import seaborn as sns\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Environments\n",
    "\n",
    "--Platform--\n",
    "OS : Windows-10-10.0.19044-SP0\n",
    "--Version--\n",
    "python :  3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]\n",
    "numpy : 1.23.1\n",
    "pandas : 1.4.3\n",
    "seaborn : 0.11.2\n",
    "\"\"\"\n",
    "\n",
    "print('--Platform--')\n",
    "print('OS :', platform.platform())\n",
    "print('--Version--')\n",
    "print('python : ', sys.version)\n",
    "print('numpy :', np.__version__)\n",
    "print('pandas :', pd.__version__)\n",
    "print('seaborn :', sns.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Preparation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create output directories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if not os.path.isdir('../30_Output/20_Plot/400_MakeResult'):\n",
    "    os.makedirs('../30_Output/20_Plot/400_MakeResult')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Main codes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_result = pd.read_csv('../30_Output/30_csv/100_CheckEigenvalues/100_Results.csv', index_col=0)\n",
    "df_result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_list = [\n",
    "    {'kernel_x':'linear', 'kernel_xs':'linear', 'loc':1},\n",
    "    {'kernel_x':'linear', 'kernel_xs':str(0.5), 'loc':2},\n",
    "    {'kernel_x':'linear', 'kernel_xs':str(1.5), 'loc':3},\n",
    "    {'kernel_x':'linear', 'kernel_xs':str(2.5), 'loc':4},\n",
    "    {'kernel_x':'linear', 'kernel_xs':str(np.inf), 'loc':5},\n",
    "    {'kernel_x':str(0.5), 'kernel_xs':'linear', 'loc':6},\n",
    "    {'kernel_x':str(0.5), 'kernel_xs':str(0.5), 'loc':7},\n",
    "    {'kernel_x':str(0.5), 'kernel_xs':str(1.5), 'loc':8},\n",
    "    {'kernel_x':str(0.5), 'kernel_xs':str(2.5), 'loc':9},\n",
    "    {'kernel_x':str(0.5), 'kernel_xs':str(np.inf), 'loc':10},\n",
    "    {'kernel_x':str(1.5), 'kernel_xs':'linear', 'loc':11},\n",
    "    {'kernel_x':str(1.5), 'kernel_xs':str(0.5), 'loc':12},\n",
    "    {'kernel_x':str(1.5), 'kernel_xs':str(1.5), 'loc':13},\n",
    "    {'kernel_x':str(1.5), 'kernel_xs':str(2.5), 'loc':14},\n",
    "    {'kernel_x':str(1.5), 'kernel_xs':str(np.inf), 'loc':15},\n",
    "    {'kernel_x':str(2.5), 'kernel_xs':'linear', 'loc':16},\n",
    "    {'kernel_x':str(2.5), 'kernel_xs':str(0.5), 'loc':17},\n",
    "    {'kernel_x':str(2.5), 'kernel_xs':str(1.5), 'loc':18},\n",
    "    {'kernel_x':str(2.5), 'kernel_xs':str(2.5), 'loc':19},\n",
    "    {'kernel_x':str(2.5), 'kernel_xs':str(np.inf), 'loc':20},\n",
    "    {'kernel_x':str(np.inf), 'kernel_xs':'linear', 'loc':21},\n",
    "    {'kernel_x':str(np.inf), 'kernel_xs':str(0.5), 'loc':22},\n",
    "    {'kernel_x':str(np.inf), 'kernel_xs':str(1.5), 'loc':23},\n",
    "    {'kernel_x':str(np.inf), 'kernel_xs':str(2.5), 'loc':24},\n",
    "    {'kernel_x':str(np.inf), 'kernel_xs':str(np.inf), 'loc':25}\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure(figsize=(30,15))\n",
    "# Loop for subplots\n",
    "for i_plt in range(len(plot_list)):\n",
    "    print(plot_list[i_plt]['loc'])\n",
    "    \n",
    "    df_result_tmp = df_result[(df_result['kernel_x']==plot_list[i_plt]['kernel_x'])&(df_result['kernel_xs']==plot_list[i_plt]['kernel_xs'])]\n",
    "    df_melt = df_result_tmp.melt(id_vars=['kernel_x','kernel_xs', 'BasisDupl', 'itr'])\n",
    "    \n",
    "    df_melt['Dupl for plot']=0\n",
    "    # Displace three types of error bars\n",
    "    for i_loc in df_melt.index:\n",
    "        if df_melt.loc[[i_loc],['variable']].values=='s_x':\n",
    "            df_melt.loc[[i_loc], ['Dupl for plot']]=df_melt.loc[[i_loc], ['BasisDupl']].values+0.1\n",
    "        if df_melt.loc[[i_loc],['variable']].values=='s_xs':\n",
    "            df_melt.loc[[i_loc], ['Dupl for plot']]=df_melt.loc[[i_loc], ['BasisDupl']].values-0.1\n",
    "        if df_melt.loc[[i_loc],['variable']].values=='s_xxs':\n",
    "            df_melt.loc[[i_loc], ['Dupl for plot']]=df_melt.loc[[i_loc], ['BasisDupl']].values\n",
    "    ax = fig.add_subplot(5, 5, plot_list[i_plt]['loc'])\n",
    "\n",
    "    snsfig = sns.lineplot(\n",
    "            data=df_melt, \n",
    "            x='Dupl for plot', \n",
    "            y='value', \n",
    "            hue='variable', \n",
    "            markers=True, \n",
    "            ci=90, \n",
    "            style='variable', \n",
    "            err_style='bars', \n",
    "            dashes=False, \n",
    "            palette=[\n",
    "                matplotlib.colors.to_rgb('steelblue') + (0.7,),\n",
    "                matplotlib.colors.to_rgb('darkgreen') + (0.7,),\n",
    "                matplotlib.colors.to_rgb('indianred') + (1,)\n",
    "            ], \n",
    "            lw=2, \n",
    "            err_kws={'lw':2},\n",
    "            legend=False\n",
    "        )\n",
    "    x_lim = snsfig.get_xlim()\n",
    "    plt.xlim(x_lim)\n",
    "    plt.xlabel('')\n",
    "    plt.ylabel('')\n",
    "    if plot_list[i_plt]['loc']==5:\n",
    "        plt.legend(['Decay rate of '+r'$\\lambda(K_2)$','Decay rate of '+r'$\\lambda(K_3)$','Decay rate of '+r'$\\lambda(K_2 \\circ K_3)$'], bbox_to_anchor=(1.05, 0.98), loc='upper left', borderaxespad=0, fontsize=13)\n",
    "    plt.grid(color='gray', linestyle='dotted', linewidth=1, alpha=0.5)\n",
    "plt.tight_layout()\n",
    "plt.savefig('../30_Output/20_Plot/400_MakeResult/400_Lineplot.pdf')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
