{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":np"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "require 'matplotlib/iruby'\n",
    "Matplotlib::IRuby.activate\n",
    "plt = Matplotlib::Pyplot\n",
    "\n",
    "require 'pycall/import'\n",
    "include PyCall::Import\n",
    "pyimport :numpy, as: :np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "http://matplotlib.org/examples/pylab_examples/polar_demo.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "r = np.arange(0, 2, 0.01)\n",
    "theta = 2 * np.pi * r\n",
    "nil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 75900 characters]",
      "text/plain": [
       "#<Matplotlib::Figure:0x007f9407a58370 @__pyptr__=#<PyCall::PyPtr:0x007f9407a583c0 type=Figure addr=0x000001097e0470>>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ax = plt.subplot(111, projection: 'polar')\n",
    "ax.plot(theta, r)\n",
    "ax.set_rmax(2)\n",
    "ax.set_rticks([0.5, 1, 1.5, 2])   # less radial ticks\n",
    "ax.set_rlabel_position(-22.5)  # get radial labels away from plotted line\n",
    "ax.grid(true)\n",
    "\n",
    "ax.set_title(\"A line plot on a polar axis\", va: 'bottom')\n",
    "nil"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "http://matplotlib.org/examples/pie_and_polar_charts/polar_scatter_demo.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 150\n",
    "r = 2 * np.random.rand(n)\n",
    "theta = 2 * np.pi * np.random.rand(n)\n",
    "area = 200 * r**2\n",
    "colors = theta\n",
    "nil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 135116 characters]",
      "text/plain": [
       "#<Matplotlib::Figure:0x007f9407945500 @__pyptr__=#<PyCall::PyPtr:0x007f9407945528 type=Figure addr=0x00000109a4b908>>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "#<Object:0x007f94079472d8 @__pyptr__=#<PyCall::PyPtr:0x007f94079472b0 type=PathCollection addr=0x000001098a54a8>>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ax = plt.subplot(111, projection: 'polar')\n",
    "c = ax.scatter(theta, r, c: colors, s: area, cmap: 'hsv', alpha: 0.75)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "http://matplotlib.org/examples/pie_and_polar_charts/polar_bar_demo.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "n = 20\n",
    "theta = np.linspace(0.0, 2 * np.pi, n, endpoint: false)\n",
    "radii = 10 * np.random.rand(n)\n",
    "width = np.pi / 4 * np.random.rand(n)\n",
    "nil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 98700 characters]",
      "text/plain": [
       "#<Matplotlib::Figure:0x007f940926b908 @__pyptr__=#<PyCall::PyPtr:0x007f940926b930 type=Figure addr=0x00000109b60d30>>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ax = plt.subplot(111, projection: 'polar')\n",
    "bars = ax.bar(theta, radii, width: width, bottom: 0.0)\n",
    "\n",
    "# TODO: I want to the following line in `PyCall.zip(radii, bars).each do |r, bar|`\n",
    "radii.tolist.zip(PyCall::List.new(bars)) do |r, bar|\n",
    "  # r = radii[i]\n",
    "  bar.set_facecolor(plt.cm.viridis(r / 10.0))\n",
    "  bar.set_alpha(0.5)\n",
    "end\n",
    "\n",
    "nil"
   ]
  },
  {
   "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
}
