{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'matplotlib.pyplot' from '/Users/mrkn/.pyenv/versions/3.6.1/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py'>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "require 'matplotlib/iruby'\n",
    "Matplotlib::IRuby.activate\n",
    "\n",
    "require 'pycall/import'\n",
    "include PyCall::Import\n",
    "\n",
    "pyimport 'numpy', as: 'np'\n",
    "plt = Matplotlib::Pyplot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Original Python code is here:\n",
    "- https://matplotlib.org/examples/showcase/xkcd.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 61684 characters]",
      "text/plain": [
       "<matplotlib.figure.Figure object at 0x10a824630>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 54440 characters]",
      "text/plain": [
       "<matplotlib.figure.Figure object at 0x10aaae6a0>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plt.xkcd do\n",
    "  # Based on \"Stove Ownership\" from XKCD by Randall Monroe\n",
    "  # http://xkcd.com/418/\n",
    "\n",
    "  fig = plt.figure()\n",
    "  ax = fig.add_axes([0.1, 0.2, 0.8, 0.7])\n",
    "  ax.spines['right'].set_color('none')\n",
    "  ax.spines['top'].set_color('none')\n",
    "  plt.xticks([])\n",
    "  plt.yticks([])\n",
    "  ax.set_ylim([-30, 10])\n",
    "\n",
    "  data = np.ones(100)\n",
    "  data[70..-1] -= np.arange(30)\n",
    "\n",
    "  plt.annotate(\n",
    "    \"THE DAY I REALIZED\\nI COULD COOK BACON\\nWHENEVER I WANTED\",\n",
    "    xy: [70, 1],\n",
    "    arrowprops: { arrowstyle: '->' },\n",
    "    xytext: [15, -10]\n",
    "  )\n",
    "\n",
    "  plt.plot(data)\n",
    "\n",
    "  plt.xlabel('time')\n",
    "  plt.ylabel('my overall health')\n",
    "  fig.text(\n",
    "    0.5, 0.05,\n",
    "    '\"Stove Ownership\" from xkcd by Randall Monroe',\n",
    "    ha: 'center'\n",
    "  )\n",
    "\n",
    "  # Based on \"The Data So Far\" from XKCD by Randall Monroe\n",
    "  # http://xkcd.com/373/\n",
    "\n",
    "  fig = plt.figure()\n",
    "  ax = fig.add_axes([0.1, 0.2, 0.8, 0.7])\n",
    "  ax.bar([0, 1], [0, 100], 0.25)\n",
    "  ax.spines['right'].set_color('none')\n",
    "  ax.spines['top'].set_color('none')\n",
    "  ax.xaxis.set_ticks_position('bottom')\n",
    "  ax.set_xticks([0, 1])\n",
    "  ax.set_xlim([-0.5, 1.5])\n",
    "  ax.set_ylim([0, 110])\n",
    "  ax.set_xticklabels([\"CONFIRMED BY\\nEXPERIMENT\", \"REFUTED BY\\nEXPERIMENT\"])\n",
    "  plt.yticks([])\n",
    "\n",
    "  plt.title(\"CLAIMS OF SUPERNATURAL POWERS\")\n",
    "\n",
    "  fig.text(\n",
    "    0.5, 0.05,\n",
    "    '\"The Data So Far\" from xkcd by Randall Monroe',\n",
    "    ha: 'center'\n",
    "  )\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Ruby 2.4.1",
   "language": "ruby",
   "name": "ruby"
  },
  "language_info": {
   "file_extension": ".rb",
   "mimetype": "application/x-ruby",
   "name": "ruby",
   "version": "2.4.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
