{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from collections import OrderedDict\n",
    "import numpy as np\n",
    "from bokeh.charts import BoxPlot, output_notebook, show\n",
    "from bokeh.sampledata.olympics2014 import data\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "data = {d['abbr']: d['medals'] for d in data['data'] if d['medals']['total'] > 0}\n",
    "\n",
    "countries = sorted(data.keys(), key=lambda x: data[x]['total'], reverse=True)\n",
    "\n",
    "gold = np.array([data[abbr]['gold'] for abbr in countries], dtype=np.float)\n",
    "silver = np.array([data[abbr]['silver'] for abbr in countries], dtype=np.float)\n",
    "bronze = np.array([data[abbr]['bronze'] for abbr in countries], dtype=np.float)\n",
    "\n",
    "medals = OrderedDict(bronze=bronze, silver=silver, gold=gold, fake=gold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "boxplot = BoxPlot(\n",
    "    medals, title=\"boxplot, dict input\", xlabel=\"medal type\", ylabel=\"medal count\", \n",
    "    width=600, height=400, marker=\"circle\", outliers=True)\n",
    "show(boxplot)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from blaze import Data\n",
    "from pandas import DataFrame\n",
    "\n",
    "bmedals = Data(DataFrame(medals))\n",
    "boxplot = BoxPlot(bmedals, title=\"boxplot, blaze input\", xlabel=\"medal type\", ylabel=\"medal count\", \n",
    "             width=800, height=600, notebook=True, marker=\"circle\", outliers=True)\n",
    "show(boxplot)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
