{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cifar10.pckl                  line.pckl\n",
      "fashion.pckl                  mnist-cifar10-separated.pckl\n",
      "line-cifar10-separated.pckl   mnist-cifar10.pckl\n",
      "line-cifar10.pckl             mnist.pckl\n",
      "line-mnist-separated.pckl     random.pckl\n",
      "line-mnist.pckl\n"
     ]
    }
   ],
   "source": [
    "!ls ../datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle\n",
    "import numpy as np\n",
    "\n",
    "data = pickle.load(open('../datasets/mnist-cifar10-separated.pckl', 'rb'))\n",
    "X = data['X_train']\n",
    "y = data['y_train']\n",
    "\n",
    "indices = np.arange(len(y))\n",
    "\n",
    "samples = np.random.choice(indices, 16)\n",
    "Xs = X[samples]\n",
    "ys = y[samples]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 47976 characters]\n",
      "text/plain": [
       "<Figure size 648x936 with 16 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# https://stackoverflow.com/questions/46615554/how-to-display-multiple-images-in-one-figure-correctly/46616645\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "w = h = 28\n",
    "fig = plt.figure(figsize=(9, 13))\n",
    "columns = 4\n",
    "rows = 4\n",
    "\n",
    "# ax enables access to manipulate each of subplots\n",
    "axes = []\n",
    "\n",
    "for i in range(columns*rows):\n",
    "    img = Xs[i]\n",
    "    ax = fig.add_subplot(rows, columns, i+1) \n",
    "    ax.set_title(ys[i], fontsize=30)\n",
    "    ax.axis('off')\n",
    "    plt.imshow(img, cmap='gray', vmin=0, vmax=255)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig('../../../Downloads/mix-mnist-cifar10-separated.png', dpi=300)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
