{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from bokeh.sampledata import us_counties, unemployment\n",
    "from bokeh.plotting import figure, show, output_notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "county_xs=[\n",
    "    us_counties.data[code]['lons'] for code in us_counties.data\n",
    "    if us_counties.data[code]['state'] == 'tx'\n",
    "]\n",
    "county_ys=[\n",
    "    us_counties.data[code]['lats'] for code in us_counties.data\n",
    "    if us_counties.data[code]['state'] == 'tx'\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "colors = [\"#F1EEF6\", \"#D4B9DA\", \"#C994C7\", \"#DF65B0\", \"#DD1C77\", \"#980043\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "county_colors = []\n",
    "for county_id in us_counties.data:\n",
    "    if us_counties.data[county_id]['state'] != 'tx':\n",
    "        continue\n",
    "    try:\n",
    "        rate = unemployment.data[county_id]\n",
    "        idx = min(int(rate/2), 5)\n",
    "        county_colors.append(colors[idx])\n",
    "    except KeyError:\n",
    "        county_colors.append(\"black\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "p = figure(title=\"Texas Unemployment 2009\")\n",
    "p.patches(county_xs, county_ys, \n",
    "    fill_color=county_colors, fill_alpha=0.7,\n",
    "    line_color=\"white\", line_width=0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "show(p)"
   ]
  },
  {
   "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
}
