{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from bokeh.charts import HeatMap, output_notebook, show\n",
    "from bokeh.palettes import Blues9 as palette\n",
    "palette = palette[::-1]\n",
    "from bokeh.sampledata.unemployment1948 import data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "df = data[data.columns[:-1]]\n",
    "df2 = df.set_index(df[df.columns[0]].astype(str))\n",
    "df2.drop(df.columns[0], axis=1, inplace=True)\n",
    "df3 = df2.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "hm = HeatMap(\n",
    "    df3, palette=palette, xlabel='Years since 1948', ylabel='Months', \n",
    "    title=\"Unemployment, pandas input\", height=400, width=1000)\n",
    "show(hm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "hm_data = df3.values.T\n",
    "hm = HeatMap(\n",
    "    hm_data, palette=palette, xlabel='Years since 1948', ylabel='Months', \n",
    "    title=\"Unemployment, array input\", height=400, width=1000)\n",
    "show(hm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "simple_df = pd.DataFrame(\n",
    "    {'apples':[4,5,8,12,4], 'pears':[6,5,4,8,7], 'bananas':[1,2,4,8,12]}, \n",
    "    index=['2009', '2010', '2011', '2012', '2013']\n",
    ")\n",
    "hm = HeatMap(\n",
    "    simple_df, palette=palette, title=\"Fruit comsumption per year\", height=300, width=500)\n",
    "show(hm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    from blaze import Data\n",
    "    simple_b = Data(simple_df)\n",
    "    hm = HeatMap(simple_b, palette=palette, title=\"Fruit comsumption per year\", notebook=True, height=400, width=1000)\n",
    "    show(hm)\n",
    "except ImportError:\n",
    "    # seems that blaze is not installed\n",
    "    pass"
   ]
  },
  {
   "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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
