{
 "metadata": {
  "name": "",
  "signature": "sha256:9b64090db9bc85e8ea9253be861bc4772c459b9484781e39afc01ebb9104d27e"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import bokeh\n",
      "bokeh.load_notebook()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from collections import OrderedDict\n",
      "\n",
      "import numpy as np\n",
      "\n",
      "from bokeh.charts import Bar\n",
      "from bokeh.sampledata.olympics2014 import data as original_data\n",
      "\n",
      "data = {d['abbr']: d['medals'] for d in original_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)\n",
      "\n",
      "bar = Bar(medals, countries, title=\"grouped, dict_input\", xlabel=\"countries\", ylabel=\"medals\", \n",
      "          legend=True, width=800, height=600, notebook=True)\n",
      "bar.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "bar.stacked(True)\n",
      "bar.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "import pandas as pd\n",
      "df = pd.DataFrame(medals, index=countries)\n",
      "\n",
      "bar = Bar(df, title=\"grouped, df_input\", xlabel=\"countries\", ylabel=\"medals\", legend=True, width=800, height=600, notebook=True, stacked=True)\n",
      "bar.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "bar.stacked(False)\n",
      "bar.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from collections import OrderedDict\n",
      "\n",
      "medals = [bronze, silver, gold]\n",
      "\n",
      "bar = Bar(medals, countries)\n",
      "bar.title(\"stacked, dict_input\").xlabel(\"countries\").ylabel(\"medals\").legend(True).width(600).height(400).stacked(False).notebook().show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "medals = np.array([bronze, silver, gold])\n",
      "bar = Bar(df)\n",
      "bar.title(\"stacked, df_input\").xlabel(\"countries\").ylabel(\"medals\").legend(True).width(600).height(400).stacked().notebook().show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}