{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "filled-multiple",
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# %matplotlib notebook\n",
    "from pathlib import Path\n",
    "import numpy as np\n",
    "import matplotlib\n",
    "from matplotlib import cm\n",
    "matplotlib.use(\"agg\")\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.ticker as ticker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "supreme-basis",
   "metadata": {},
   "outputs": [],
   "source": [
    "def visualize_syn(save_path):\n",
    "    save_dir = (save_path / '..').resolve()\n",
    "    save_dir.mkdir(parents=True, exist_ok=True)\n",
    "    \n",
    "    dpi, width, height = 50, 2000, 1000\n",
    "    figsize = width / float(dpi), height / float(dpi)\n",
    "    LabelSize, font_gap = 30, 4\n",
    "    \n",
    "    fig = plt.figure(figsize=figsize)\n",
    "    \n",
    "    times = np.arange(0, np.pi * 100, 0.1)\n",
    "    num = len(times)\n",
    "    x = []\n",
    "    for i in range(num):\n",
    "        scale = (i + 1.) / num * 4\n",
    "        value = times[i] * scale\n",
    "        x.append(np.sin(value) * (1.3 - scale))\n",
    "    x = np.array(x)\n",
    "    y = np.cos( x * x - 0.3 * x )\n",
    "    \n",
    "    cur_ax = fig.add_subplot(2, 1, 1)\n",
    "    cur_ax.plot(times, x)\n",
    "    cur_ax.set_xlabel(\"time\", fontsize=LabelSize)\n",
    "    cur_ax.set_ylabel(\"x\", fontsize=LabelSize)\n",
    "    for tick in cur_ax.xaxis.get_major_ticks():\n",
    "        tick.label.set_fontsize(LabelSize - font_gap)\n",
    "        tick.label.set_rotation(30)\n",
    "    for tick in cur_ax.yaxis.get_major_ticks():\n",
    "        tick.label.set_fontsize(LabelSize - font_gap)\n",
    "        \n",
    "    \n",
    "    cur_ax = fig.add_subplot(2, 1, 2)\n",
    "    cur_ax.plot(times, y)\n",
    "    cur_ax.set_xlabel(\"time\", fontsize=LabelSize)\n",
    "    cur_ax.set_ylabel(\"f(x)\", fontsize=LabelSize)\n",
    "    for tick in cur_ax.xaxis.get_major_ticks():\n",
    "        tick.label.set_fontsize(LabelSize - font_gap)\n",
    "        tick.label.set_rotation(30)\n",
    "    for tick in cur_ax.yaxis.get_major_ticks():\n",
    "        tick.label.set_fontsize(LabelSize - font_gap)\n",
    "        \n",
    "    # fig.tight_layout()\n",
    "    # plt.subplots_adjust(wspace=0.05)#, hspace=0.4)\n",
    "    fig.savefig(save_path, dpi=dpi, bbox_inches=\"tight\", format=\"pdf\")\n",
    "    plt.close(\"all\")\n",
    "    # plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "shared-envelope",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Desktop is at: /Users/xuanyidong/Desktop\n"
     ]
    }
   ],
   "source": [
    "# Visualization\n",
    "home_dir = Path.home()\n",
    "desktop_dir = home_dir / 'Desktop'\n",
    "print('The Desktop is at: {:}'.format(desktop_dir))\n",
    "visualize_syn(desktop_dir / 'tot-synthetic-v0.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "romantic-ordinance",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
