{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "filled-multiple",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The root path: /Users/xuanyidong/Desktop/AutoDL-Projects\n",
      "The library path: /Users/xuanyidong/Desktop/AutoDL-Projects/lib\n"
     ]
    }
   ],
   "source": [
    "import os, sys\n",
    "import torch\n",
    "from pathlib import Path\n",
    "import numpy as np\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "__file__ = os.path.dirname(os.path.realpath(\"__file__\"))\n",
    "root_dir = (Path(__file__).parent / \"..\").resolve()\n",
    "lib_dir = (root_dir / \"lib\").resolve()\n",
    "print(\"The root path: {:}\".format(root_dir))\n",
    "print(\"The library path: {:}\".format(lib_dir))\n",
    "assert lib_dir.exists(), \"{:} does not exist\".format(lib_dir)\n",
    "if str(lib_dir) not in sys.path:\n",
    "    sys.path.insert(0, str(lib_dir))\n",
    "\n",
    "from datasets.synthetic_example import create_example_v1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "consistent-transition",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 385484 characters]\n",
      "text/plain": [
       "<Figure size 5760x2880 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def visualize_env():\n",
    "    \n",
    "    dpi, width, height = 10, 800, 400\n",
    "    figsize = width / float(dpi), height / float(dpi)\n",
    "    LabelSize, LegendFontsize, font_gap = 40, 40, 5\n",
    "\n",
    "    fig = plt.figure(figsize=figsize)\n",
    "\n",
    "    dynamic_env, _ = create_example_v1(num_per_task=250)\n",
    "    \n",
    "    timeaxis, xaxis, yaxis = [], [], []\n",
    "    for timestamp, dataset in dynamic_env:\n",
    "        num = dataset[0].shape[0]\n",
    "        timeaxis.append(torch.zeros(num) + timestamp)\n",
    "        xaxis.append(dataset[0][:,0])\n",
    "        # compute the ground truth\n",
    "        # function.set_timestamp(timestamp)\n",
    "        yaxis.append(dataset[1][:,0])\n",
    "        \n",
    "    timeaxis = torch.cat(timeaxis).numpy()\n",
    "    # import pdb; pdb.set_trace()\n",
    "    xaxis = torch.cat(xaxis).numpy()\n",
    "    yaxis = torch.cat(yaxis).numpy()\n",
    "\n",
    "    cur_ax = fig.add_subplot(2, 1, 1)\n",
    "    cur_ax.scatter(timeaxis, xaxis, color=\"k\", linestyle=\"-\", alpha=0.9, label=None)\n",
    "    cur_ax.set_xlabel(\"Time\", fontsize=LabelSize)\n",
    "    cur_ax.set_ylabel(\"X\", rotation=0, 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(10)\n",
    "    for tick in cur_ax.yaxis.get_major_ticks():\n",
    "        tick.label.set_fontsize(LabelSize - font_gap)\n",
    "    \n",
    "    cur_ax = fig.add_subplot(2, 1, 2)\n",
    "    cur_ax.scatter(timeaxis, yaxis, color=\"k\", linestyle=\"-\", alpha=0.9, label=None)\n",
    "    cur_ax.set_xlabel(\"Time\", fontsize=LabelSize)\n",
    "    cur_ax.set_ylabel(\"Y\", rotation=0, 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(10)\n",
    "    for tick in cur_ax.yaxis.get_major_ticks():\n",
    "        tick.label.set_fontsize(LabelSize - font_gap)\n",
    "    plt.show()\n",
    "\n",
    "visualize_env()"
   ]
  }
 ],
 "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
}
