{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import dautil as dl\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from IPython.display import HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "wb = dl.data.Worldbank()\n",
    "countries = wb.get_countries()[['name', 'iso2c']]\n",
    "inf_mort = wb.get_name('inf_mort')\n",
    "gdp_pcap = wb.get_name('gdp_pcap')\n",
    "df = wb.download(country=countries['iso2c'],\n",
    "                 indicator=[inf_mort, gdp_pcap],\n",
    "                 start=2010, end=2010).dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "loglog = df.applymap(np.log10)\n",
    "x = loglog[gdp_pcap]\n",
    "y = loglog[inf_mort]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "dl.options.mimic_seaborn()\n",
    "context = dl.nb.Context('transforming_down')\n",
    "dl.nb.RcWidget(context)\n",
    "dl.nb.LabelWidget(2, 1, context)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sp = dl.plotting.Subplotter(2, 1, context)\n",
    "xvar = 'GDP per capita'\n",
    "sp.label(xlabel_params=xvar)\n",
    "sp.ax.set_ylim([0, 200])\n",
    "sp.ax.scatter(df[gdp_pcap], df[inf_mort])\n",
    "\n",
    "sp.next_ax()\n",
    "sp.ax.scatter(x, y, label='Transformed')\n",
    "dl.plotting.plot_polyfit(sp.ax, x, y)\n",
    "sp.label(xlabel_params=xvar)\n",
    "plt.tight_layout()\n",
    "HTML(dl.report.HTMLBuilder().watermark())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
