{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from collections import OrderedDict\n",
    "import pandas as pd\n",
    "from bokeh.charts import Scatter, output_notebook, show\n",
    "from bokeh.sampledata.iris import flowers\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "setosa = flowers[(flowers.species == \"setosa\")][[\"petal_length\", \"petal_width\"]]\n",
    "versicolor = flowers[(flowers.species == \"versicolor\")][[\"petal_length\", \"petal_width\"]]\n",
    "virginica = flowers[(flowers.species == \"virginica\")][[\"petal_length\", \"petal_width\"]]\n",
    "\n",
    "xyvalues = OrderedDict([\n",
    "    (\"setosa\", setosa.values), \n",
    "    (\"versicolor\", versicolor.values), \n",
    "    (\"virginica\", virginica.values)\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "scatter = Scatter(\n",
    "    xyvalues, title=\"iris dataset, dict input\", \n",
    "    xlabel=\"petal_length\", ylabel=\"petal_width\", legend='top_left')\n",
    "show(scatter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "groupped_df = flowers[[\"petal_length\", \"petal_width\", \"species\"]].groupby(\"species\")\n",
    "scatter = Scatter(\n",
    "    groupped_df, title=\"iris dataset, grouped pandas input\", \n",
    "    xlabel=\"petal_length\", ylabel=\"petal_width\", legend='top_left')\n",
    "show(scatter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pdict = OrderedDict()\n",
    "for i in groupped_df.groups.keys():\n",
    "    labels = groupped_df.get_group(i).columns\n",
    "    xname = labels[0]\n",
    "    yname = labels[1]\n",
    "    x = getattr(groupped_df.get_group(i), xname)\n",
    "    y = getattr(groupped_df.get_group(i), yname)\n",
    "    pdict[i] = list(zip(x, y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "df = pd.DataFrame(pdict)\n",
    "scatter = Scatter(\n",
    "    df, title=\"iris dataset, pandas input\", \n",
    "    xlabel=\"petal_length\", ylabel=\"petal_width\", legend='top_left')\n",
    "show(scatter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "scatter = Scatter(\n",
    "    list(xyvalues.values()), title=\"iris dataset, list input\", \n",
    "    xlabel=\"petal_length\", ylabel=\"petal_width\", legend='top_left')\n",
    "show(scatter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from blaze import Data\n",
    "\n",
    "b = Data(df)\n",
    "scatter = Scatter(b, title=\"iris dataset, dict_input\", xlabel=\"petal_length\",\n",
    "                  ylabel=\"petal_width\", legend='top_left')\n",
    "show(scatter)"
   ]
  },
  {
   "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
}
