{
 "metadata": {
  "name": "",
  "signature": "sha256:f8a276aa85e196a8df5e2c59dc827d87bdf39340becaead7676dfeb064f29a12"
 },
 "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",
      "from bokeh.charts import Histogram\n",
      "\n",
      "mu, sigma = 0, 0.5\n",
      "normal = np.random.normal(mu, sigma, 1000)\n",
      "\n",
      "normal_dist = OrderedDict(normal=normal)\n",
      "\n",
      "hist = Histogram(normal_dist, bins=50, mu=mu, sigma=sigma,\n",
      "                 title=\"kwargs, dict_input\", ylabel=\"frequency\", legend=\"top_left\",\n",
      "                 width=400, height=350, notebook=True)\n",
      "hist.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "df = pd.DataFrame(normal_dist)\n",
      "\n",
      "hist = Histogram(df, bins=50, mu=mu, sigma=sigma,\n",
      "                 title=\"no_tools, df_input\", ylabel=\"frequency\", legend=\"top_left\",\n",
      "                 tools=True, width=400, height=350, notebook=True)\n",
      "hist.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from collections import OrderedDict\n",
      "\n",
      "import numpy as np\n",
      "from bokeh.charts import Histogram\n",
      "\n",
      "mu, sigma = 0, 0.5\n",
      "normal = np.random.normal(mu, sigma, 1000)\n",
      "lognormal = np.random.lognormal(mu, sigma, 1000)\n",
      "\n",
      "distributions = OrderedDict(normal=normal, lognormal=lognormal)\n",
      "\n",
      "hist = Histogram(distributions, bins=50, notebook=True)\n",
      "hist.title(\"chained_methods, dict_input\").ylabel(\"frequency\").legend(True).width(400).height(350).show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "df = pd.DataFrame(distributions)\n",
      "\n",
      "hist = Histogram(df, bins=50, notebook=True)\n",
      "hist.title(\"chained_methods, df_input\").ylabel(\"frequency\").width(400).height(350).show()"
     ],
     "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\n",
      "\n",
      "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)\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": 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)\n",
      "bar.show()"
     ],
     "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\n",
      "\n",
      "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)\n",
      "\n",
      "bar = Bar(medals, countries)\n",
      "bar.title(\"stacked, dict_input\").xlabel(\"countries\").ylabel(\"medals\").legend(True).width(600).height(400).stacked().notebook().show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "df = pd.DataFrame(medals, index=countries)\n",
      "\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": [
      "from collections import OrderedDict\n",
      "\n",
      "from bokeh.charts import Scatter\n",
      "from bokeh.sampledata.iris import flowers\n",
      "\n",
      "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([(\"setosa\", setosa.values), (\"versicolor\", versicolor.values), (\"virginica\", virginica.values)])\n",
      "\n",
      "scatter = Scatter(xyvalues)\n",
      "scatter.title(\"iris dataset, dict_input\").xlabel(\"petal_length\").ylabel(\"petal_width\").legend(\"top_left\").width(600).height(400).notebook().show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "\n",
      "xyvalues = OrderedDict([(\"setosa\", setosa), (\"versicolor\", versicolor), (\"virginica\", virginica)])\n",
      "df = pd.concat(xyvalues, axis=1, names=[\"l0\", \"l1\"])\n",
      "\n",
      "scatter = Scatter(df)\n",
      "scatter.title(\"iris dataset, df_input\").legend(\"top_left\").width(600).height(400).notebook().show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from bokeh.charts import Scatter\n",
      "from bokeh.sampledata.iris import flowers\n",
      "\n",
      "df = flowers[[\"petal_length\", \"petal_width\", \"species\"]]\n",
      "g = df.groupby(\"species\")\n",
      "\n",
      "scatter = Scatter(g)\n",
      "scatter.title(\"iris dataset, gp_by_input\").legend(\"top_left\").width(600).height(400).notebook().show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}