From 1e5e12f4fc6f2fda8f6cfc8899cc369c3756a758 Mon Sep 17 00:00:00 2001 From: nielsenlouise Date: Thu, 3 Mar 2016 16:42:15 -0500 Subject: [PATCH 01/16] copy-pasting creatively and making it do some of what we want in time for the mid-project check-in --- ...learning_bokeh_in_jupyter-checkpoint.ipynb | 490 ++++++++++++++++++ csv_read_for_pandas.py | 3 + geojson.html | 28 + gmap_plot.html | 28 + google_maps_stuff.py | 48 ++ learning_bokeh_in_jupyter.ipynb | 380 ++++++++++++++ play_with_bokeh_and_texas.py | 45 ++ test_bokeh_data.csv | 3 + testing_stuff.py | 12 + texas.html | 28 + 10 files changed, 1065 insertions(+) create mode 100644 .ipynb_checkpoints/learning_bokeh_in_jupyter-checkpoint.ipynb create mode 100644 csv_read_for_pandas.py create mode 100644 geojson.html create mode 100644 gmap_plot.html create mode 100644 google_maps_stuff.py create mode 100644 learning_bokeh_in_jupyter.ipynb create mode 100644 play_with_bokeh_and_texas.py create mode 100644 test_bokeh_data.csv create mode 100644 testing_stuff.py create mode 100644 texas.html diff --git a/.ipynb_checkpoints/learning_bokeh_in_jupyter-checkpoint.ipynb b/.ipynb_checkpoints/learning_bokeh_in_jupyter-checkpoint.ipynb new file mode 100644 index 0000000..8df5d25 --- /dev/null +++ b/.ipynb_checkpoints/learning_bokeh_in_jupyter-checkpoint.ipynb @@ -0,0 +1,490 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here we are learning to bokeh in jupyter notebooks." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Using data directory: /home/lnielsen/.bokeh/data\n", + "Downloading: CGM.csv (1589982 bytes)\n", + " 1589982 [100.00%]\n", + "Downloading: US_Counties.zip (3182088 bytes)\n", + " 3182088 [100.00%]\n", + "Unpacking: US_Counties.csv\n", + "Downloading: us_cities.json (713565 bytes)\n", + " 713565 [100.00%]\n", + "Downloading: unemployment09.csv (253301 bytes)\n", + " 253301 [100.00%]\n", + "Downloading: AAPL.csv (166698 bytes)\n", + " 166698 [100.00%]\n", + "Downloading: FB.csv (9706 bytes)\n", + " 9706 [100.00%]\n", + "Downloading: GOOG.csv (113894 bytes)\n", + " 113894 [100.00%]\n", + "Downloading: IBM.csv (165625 bytes)\n", + " 165625 [100.00%]\n", + "Downloading: MSFT.csv (161614 bytes)\n", + " 161614 [100.00%]\n", + "Downloading: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip (5148539 bytes)\n", + " 5148539 [100.00%]\n", + "Unpacking: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.csv\n", + "Downloading: gapminder_fertility.csv (64346 bytes)\n", + " 64346 [100.00%]\n", + "Downloading: gapminder_population.csv (94509 bytes)\n", + " 94509 [100.00%]\n", + "Downloading: gapminder_life_expectancy.csv (73243 bytes)\n", + " 73243 [100.00%]\n", + "Downloading: gapminder_regions.csv (7781 bytes)\n", + " 7781 [100.00%]\n", + "Downloading: world_cities.zip (646858 bytes)\n", + " 646858 [100.00%]\n", + "Unpacking: world_cities.csv\n", + "Downloading: airports.json (6373 bytes)\n", + " 6373 [100.00%]\n", + "Downloading: movies.db.zip (5067833 bytes)\n", + " 5067833 [100.00%]\n", + "Unpacking: movies.db\n" + ] + } + ], + "source": [ + "import bokeh.sampledata; bokeh.sampledata.download()\n", + "from bokeh.models import HoverTool\n", + "from bokeh.plotting import figure, show, output_file, ColumnDataSource\n", + "from bokeh.sampledata.us_counties import data as counties\n", + "from bokeh.sampledata.unemployment import data as unemployment\n", + "\n", + "\n", + "counties = {\n", + " code: county for code, county in counties.items() if county[\"state\"] == \"ma\"\n", + "}\n", + "\n", + "county_xs = [county[\"lons\"] for county in counties.values()]\n", + "county_ys = [county[\"lats\"] for county in counties.values()]\n", + "\n", + "colors = [\"#F1EEF6\", \"#D4B9DA\", \"#C994C7\", \"#DF65B0\", \"#DD1C77\", \"#980043\"]\n", + "\n", + "county_names = [county['name'] for county in counties.values()]\n", + "county_rates = [unemployment[county_id] for county_id in counties]\n", + "county_colors = [colors[int(rate/3)] for rate in county_rates]\n", + "\n", + "source = ColumnDataSource(data=dict(\n", + " x=county_xs,\n", + " y=county_ys,\n", + " color=county_colors,\n", + " name=county_names,\n", + " rate=county_rates,\n", + "))\n", + "\n", + "TOOLS=\"pan,wheel_zoom,box_zoom,reset,hover,save\"\n", + "\n", + "p = figure(title=\"Texas Unemployment 2009\", tools=TOOLS)\n", + "\n", + "p.patches('x', 'y', source=source,\n", + " fill_color='color', fill_alpha=0.7,\n", + " line_color=\"white\", line_width=0.5)\n", + "\n", + "hover = p.select_one(HoverTool)\n", + "hover.point_policy = \"follow_mouse\"\n", + "hover.tooltips = [\n", + " (\"Name\", \"@name\"),\n", + " (\"Unemployment rate)\", \"@rate%\"),\n", + " (\"(Long, Lat)\", \"($x, $y)\"),\n", + "]\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + " \n", + " Loading BokehJS ...\n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "\n", + "(function(global) {\n", + " function now() {\n", + " return new Date();\n", + " }\n", + "\n", + " if (typeof (window._bokeh_onload_callbacks) === \"undefined\") {\n", + " window._bokeh_onload_callbacks = [];\n", + " }\n", + "\n", + " function run_callbacks() {\n", + " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", + " delete window._bokeh_onload_callbacks\n", + " console.info(\"Bokeh: all callbacks have finished\");\n", + " }\n", + "\n", + " function load_libs(js_urls, callback) {\n", + " window._bokeh_onload_callbacks.push(callback);\n", + " if (window._bokeh_is_loading > 0) {\n", + " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", + " return null;\n", + " }\n", + " if (js_urls == null || js_urls.length === 0) {\n", + " run_callbacks();\n", + " return null;\n", + " }\n", + " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", + " window._bokeh_is_loading = js_urls.length;\n", + " for (var i = 0; i < js_urls.length; i++) {\n", + " var url = js_urls[i];\n", + " var s = document.createElement('script');\n", + " s.src = url;\n", + " s.async = false;\n", + " s.onreadystatechange = s.onload = function() {\n", + " window._bokeh_is_loading--;\n", + " if (window._bokeh_is_loading === 0) {\n", + " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", + " run_callbacks()\n", + " }\n", + " };\n", + " s.onerror = function() {\n", + " console.warn(\"failed to load library \" + url);\n", + " };\n", + " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", + " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", + " }\n", + " };\n", + "\n", + " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.1.min.js'];\n", + "\n", + " var inline_js = [\n", + " function(Bokeh) {\n", + " Bokeh.set_log_level(\"info\");\n", + " },\n", + " \n", + " function(Bokeh) {\n", + " Bokeh.$(\"#44e8e7a5-7363-4bde-ba9a-36305a462ef9\").text(\"BokehJS successfully loaded\");\n", + " },\n", + " function(Bokeh) {\n", + " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", + " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", + " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", + " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", + " }\n", + " ];\n", + "\n", + " function run_inline_js() {\n", + " for (var i = 0; i < inline_js.length; i++) {\n", + " inline_js[i](window.Bokeh);\n", + " }\n", + " }\n", + "\n", + " if (window._bokeh_is_loading === 0) {\n", + " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", + " run_inline_js();\n", + " } else {\n", + " load_libs(js_urls, function() {\n", + " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", + " run_inline_js();\n", + " });\n", + " }\n", + "}(this));" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from bokeh.io import output_notebook\n", + "\n", + "output_notebook()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "

<Bokeh Notebook handle for In[20]>

" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "show(p)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "

<Bokeh Notebook handle for In[13]>

" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/csv_read_for_pandas.py b/csv_read_for_pandas.py new file mode 100644 index 0000000..ce071fe --- /dev/null +++ b/csv_read_for_pandas.py @@ -0,0 +1,3 @@ +import pandas as pd + +print pd.read_csv('test_bokeh_data.csv') diff --git a/geojson.html b/geojson.html new file mode 100644 index 0000000..e1d3c55 --- /dev/null +++ b/geojson.html @@ -0,0 +1,28 @@ + + + + + + Bokeh Plot + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/gmap_plot.html b/gmap_plot.html new file mode 100644 index 0000000..b8f279c --- /dev/null +++ b/gmap_plot.html @@ -0,0 +1,28 @@ + + + + + + Bokeh Plot + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/google_maps_stuff.py b/google_maps_stuff.py new file mode 100644 index 0000000..622164b --- /dev/null +++ b/google_maps_stuff.py @@ -0,0 +1,48 @@ +from bokeh.models import HoverTool +from bokeh.plotting import figure +from bokeh.plotting import ColumnDataSource as plotColumnDataSource +from bokeh.io import output_file, show +from bokeh.models import ( + GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool +) + +map_options = GMapOptions(lat=42.3601, lng=-71.0589, map_type="roadmap", zoom=9) + +plot = GMapPlot( + x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, title="Austin" +) + +# source = ColumnDataSource( +# data=dict( +# lat=[42.3601, 42.2926], +# lon=[-71.0589, -71.2644], +# ) +# ) + +source = plotColumnDataSource(data=dict( + x=[-71.0589, -71.2644], + y=[42.3601, 42.2926], + name=['Boston', 'Olin'], + address=['Boston Rite Aid', 'Olin The Awesomest'] +)) + +circle = Circle(x="x", y="y", size=15, fill_color="blue", fill_alpha=0.8, line_color=None) +plot.add_glyph(source, circle) + +TOOLS="pan,wheel_zoom,box_zoom,reset,hover,save" + +p = figure(title="Our Map", tools=TOOLS) + +plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool(), HoverTool()) + +hover = plot.select_one(HoverTool) +hover.point_policy = "follow_mouse" +hover.tooltips = [ + ('Name', '@name'), + ('Title', '@address') +# ("(Long, Lat)", "($x, $y)"), +] + +# plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool(), hover()) +output_file("gmap_plot.html") +show(plot) diff --git a/learning_bokeh_in_jupyter.ipynb b/learning_bokeh_in_jupyter.ipynb new file mode 100644 index 0000000..66aed75 --- /dev/null +++ b/learning_bokeh_in_jupyter.ipynb @@ -0,0 +1,380 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here we are learning to bokeh in jupyter notebooks." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Using data directory: /home/lnielsen/.bokeh/data\n", + "Downloading: CGM.csv (1589982 bytes)\n", + " 1589982 [100.00%]\n", + "Downloading: US_Counties.zip (3182088 bytes)\n", + " 3182088 [100.00%]\n", + "Unpacking: US_Counties.csv\n", + "Downloading: us_cities.json (713565 bytes)\n", + " 713565 [100.00%]\n", + "Downloading: unemployment09.csv (253301 bytes)\n", + " 253301 [100.00%]\n", + "Downloading: AAPL.csv (166698 bytes)\n", + " 166698 [100.00%]\n", + "Downloading: FB.csv (9706 bytes)\n", + " 9706 [100.00%]\n", + "Downloading: GOOG.csv (113894 bytes)\n", + " 113894 [100.00%]\n", + "Downloading: IBM.csv (165625 bytes)\n", + " 165625 [100.00%]\n", + "Downloading: MSFT.csv (161614 bytes)\n", + " 161614 [100.00%]\n", + "Downloading: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip (5148539 bytes)\n", + " 5148539 [100.00%]\n", + "Unpacking: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.csv\n", + "Downloading: gapminder_fertility.csv (64346 bytes)\n", + " 64346 [100.00%]\n", + "Downloading: gapminder_population.csv (94509 bytes)\n", + " 94509 [100.00%]\n", + "Downloading: gapminder_life_expectancy.csv (73243 bytes)\n", + " 73243 [100.00%]\n", + "Downloading: gapminder_regions.csv (7781 bytes)\n", + " 7781 [100.00%]\n", + "Downloading: world_cities.zip (646858 bytes)\n", + " 646858 [100.00%]\n", + "Unpacking: world_cities.csv\n", + "Downloading: airports.json (6373 bytes)\n", + " 6373 [100.00%]\n", + "Downloading: movies.db.zip (5067833 bytes)\n", + " 5067833 [100.00%]\n", + "Unpacking: movies.db\n" + ] + } + ], + "source": [ + "import bokeh.sampledata; bokeh.sampledata.download()\n", + "from bokeh.models import HoverTool\n", + "from bokeh.plotting import figure, show, output_file, ColumnDataSource\n", + "from bokeh.sampledata.us_counties import data as counties\n", + "from bokeh.sampledata.unemployment import data as unemployment\n", + "\n", + "\n", + "counties = {\n", + " code: county for code, county in counties.items() if county[\"state\"] == \"ma\"\n", + "}\n", + "\n", + "county_xs = [county[\"lons\"] for county in counties.values()]\n", + "county_ys = [county[\"lats\"] for county in counties.values()]\n", + "\n", + "colors = [\"#F1EEF6\", \"#D4B9DA\", \"#C994C7\", \"#DF65B0\", \"#DD1C77\", \"#980043\"]\n", + "\n", + "county_names = [county['name'] for county in counties.values()]\n", + "county_rates = [unemployment[county_id] for county_id in counties]\n", + "county_colors = [colors[int(rate/3)] for rate in county_rates]\n", + "\n", + "source = ColumnDataSource(data=dict(\n", + " x=county_xs,\n", + " y=county_ys,\n", + " color=county_colors,\n", + " name=county_names,\n", + " rate=county_rates,\n", + "))\n", + "\n", + "TOOLS=\"pan,wheel_zoom,box_zoom,reset,hover,save\"\n", + "\n", + "p = figure(title=\"Texas Unemployment 2009\", tools=TOOLS)\n", + "\n", + "p.patches('x', 'y', source=source,\n", + " fill_color='color', fill_alpha=0.7,\n", + " line_color=\"white\", line_width=0.5)\n", + "\n", + "hover = p.select_one(HoverTool)\n", + "hover.point_policy = \"follow_mouse\"\n", + "hover.tooltips = [\n", + " (\"Name\", \"@name\"),\n", + " (\"Unemployment rate)\", \"@rate%\"),\n", + " (\"(Long, Lat)\", \"($x, $y)\"),\n", + "]\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + " \n", + " Loading BokehJS ...\n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "\n", + "(function(global) {\n", + " function now() {\n", + " return new Date();\n", + " }\n", + "\n", + " if (typeof (window._bokeh_onload_callbacks) === \"undefined\") {\n", + " window._bokeh_onload_callbacks = [];\n", + " }\n", + "\n", + " function run_callbacks() {\n", + " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", + " delete window._bokeh_onload_callbacks\n", + " console.info(\"Bokeh: all callbacks have finished\");\n", + " }\n", + "\n", + " function load_libs(js_urls, callback) {\n", + " window._bokeh_onload_callbacks.push(callback);\n", + " if (window._bokeh_is_loading > 0) {\n", + " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", + " return null;\n", + " }\n", + " if (js_urls == null || js_urls.length === 0) {\n", + " run_callbacks();\n", + " return null;\n", + " }\n", + " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", + " window._bokeh_is_loading = js_urls.length;\n", + " for (var i = 0; i < js_urls.length; i++) {\n", + " var url = js_urls[i];\n", + " var s = document.createElement('script');\n", + " s.src = url;\n", + " s.async = false;\n", + " s.onreadystatechange = s.onload = function() {\n", + " window._bokeh_is_loading--;\n", + " if (window._bokeh_is_loading === 0) {\n", + " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", + " run_callbacks()\n", + " }\n", + " };\n", + " s.onerror = function() {\n", + " console.warn(\"failed to load library \" + url);\n", + " };\n", + " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", + " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", + " }\n", + " };\n", + "\n", + " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.1.min.js'];\n", + "\n", + " var inline_js = [\n", + " function(Bokeh) {\n", + " Bokeh.set_log_level(\"info\");\n", + " },\n", + " \n", + " function(Bokeh) {\n", + " Bokeh.$(\"#44e8e7a5-7363-4bde-ba9a-36305a462ef9\").text(\"BokehJS successfully loaded\");\n", + " },\n", + " function(Bokeh) {\n", + " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", + " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", + " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", + " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", + " }\n", + " ];\n", + "\n", + " function run_inline_js() {\n", + " for (var i = 0; i < inline_js.length; i++) {\n", + " inline_js[i](window.Bokeh);\n", + " }\n", + " }\n", + "\n", + " if (window._bokeh_is_loading === 0) {\n", + " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", + " run_inline_js();\n", + " } else {\n", + " load_libs(js_urls, function() {\n", + " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", + " run_inline_js();\n", + " });\n", + " }\n", + "}(this));" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from bokeh.io import output_notebook\n", + "\n", + "output_notebook()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "

<Bokeh Notebook handle for In[20]>

" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/play_with_bokeh_and_texas.py b/play_with_bokeh_and_texas.py new file mode 100644 index 0000000..932da5c --- /dev/null +++ b/play_with_bokeh_and_texas.py @@ -0,0 +1,45 @@ +from bokeh.models import HoverTool +from bokeh.plotting import figure, show, output_file, ColumnDataSource +from bokeh.sampledata.us_counties import data as counties +from bokeh.sampledata.unemployment import data as unemployment + +counties = { + code: county for code, county in counties.items() if county["state"] == "ma" +} + +county_xs = [county["lons"] for county in counties.values()] +county_ys = [county["lats"] for county in counties.values()] + +colors = ["#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043"] + +county_names = [county['name'] for county in counties.values()] +county_rates = [unemployment[county_id] for county_id in counties] +county_colors = [colors[int(rate/3)] for rate in county_rates] + +source = ColumnDataSource(data=dict( + x=county_xs, + y=county_ys, + color=county_colors, + name=county_names, + rate=county_rates, +)) + +TOOLS = "pan, wheel_zoom, box_zoom, reset, hover, save" + +p = figure(title="Texas Unemployment 2009", tools=TOOLS) + +p.patches('x', 'y', source=source, + fill_color='color', fill_alpha=0.7, + line_color="white", line_width=0.5) + +hover = p.select_one(HoverTool) +hover.point_policy = "follow_mouse" +hover.tooltips = [ + ("Name", "@name"), + ("Unemployment rate)", "@rate%"), + ("(Long, Lat)", "($x, $y)"), +] + +output_file("texas.html", title="texas.py example") + +show(p) diff --git a/test_bokeh_data.csv b/test_bokeh_data.csv new file mode 100644 index 0000000..510de6f --- /dev/null +++ b/test_bokeh_data.csv @@ -0,0 +1,3 @@ +Name,Lat,Long +Boston,42.3601,-71.0589 +Olin College,42.2926,-71.2644 \ No newline at end of file diff --git a/testing_stuff.py b/testing_stuff.py new file mode 100644 index 0000000..80493be --- /dev/null +++ b/testing_stuff.py @@ -0,0 +1,12 @@ +from bokeh.io import output_file, show +from bokeh.models import GeoJSONDataSource +from bokeh.plotting import figure +from bokeh.sampledata.sample_geojson import geojson + + +geo_source = GeoJSONDataSource(geojson=geojson) + +p = figure() +p.circle(x='x', y='y', alpha=0.9, source=geo_source) +output_file("geojson.html") +show(p) diff --git a/texas.html b/texas.html new file mode 100644 index 0000000..df6cd05 --- /dev/null +++ b/texas.html @@ -0,0 +1,28 @@ + + + + + + texas.py example + + + + + + + + +
+ + + + \ No newline at end of file From 19d12ed16a8a01e21c4cca53e3a1762903803975 Mon Sep 17 00:00:00 2001 From: nielsenlouise Date: Thu, 3 Mar 2016 17:18:45 -0500 Subject: [PATCH 02/16] we made it hybrid! different looking map now --- gmap_plot.html | 6 +++--- google_maps_stuff.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gmap_plot.html b/gmap_plot.html index b8f279c..4a45c42 100644 --- a/gmap_plot.html +++ b/gmap_plot.html @@ -14,12 +14,12 @@ -
+
+ + + + +
+ + + + \ No newline at end of file diff --git a/mapthing.html b/mapthing.html new file mode 100644 index 0000000..5e9047a --- /dev/null +++ b/mapthing.html @@ -0,0 +1,28 @@ + + + + + + Bokeh Plot + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/model_pandas.pyc b/model_pandas.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4318d5bc7d458e8f61d0990f9c34430a647efebb GIT binary patch literal 1847 zcmcgs&2HO95FS!LwpBZJlc0bv0fPd8axsA(d@_^Uuy8{ru_ooK{ZP z%i1SlZj#Cs#wNMd-X}|6)@L%i&~>4GV#{fxo2z6vcdpS__a6?*fANfl5gdj+h!ba* zRsBo{J$B0`H=&2gU)kq>usp@Ae*j^C1z|$Qf}+b&zKajXT4E6>1@s>QF19 z7grLRQe|BRrM7X9AMnA^7Jl2&{W#~k;IWIr!TFC6Wt-}l4v}J%>fr~F4K7jBJ=zDQ ze}f(rMW6mc?MgcM+Xfwln5i!|*UPtPzZk5IA7E^+jU5=b*2XT3y|sZO;A(Z=2JK%{ zzdb{tEoakWATyu2;nA35G7jZV; z3%>nzIbep`j$vxvv?{O5opnv67m~eipSUBdt7)Mh{e+`E1_?k3Lg0TbPp(r=pVdL$ zr>nQc&B61hcrzusD9~_T^y8H-z*h7~A4`GCHb4z`v29^p_}|6BnIxqO zmn)Sqz>L3V2}Fwv%6DknjO&i`;`vhQ$NhMBQ!c6OXV@8Ew&51U)LoeQ0cR(m`7_K= ec8@>uw)XxNSKl*sq4%gI^bvR23d44^*ZBfCb*_&9 literal 0 HcmV?d00001 diff --git a/plot.html b/plot.html new file mode 100644 index 0000000..ad47c1b --- /dev/null +++ b/plot.html @@ -0,0 +1,28 @@ + + + + + + Bokeh Plot + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/resources_plot.html b/resources_plot.html new file mode 100644 index 0000000..2864366 --- /dev/null +++ b/resources_plot.html @@ -0,0 +1,28 @@ + + + + + + Bokeh Plot + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/test.csv b/test.csv new file mode 100644 index 0000000..15aef8f --- /dev/null +++ b/test.csv @@ -0,0 +1,3 @@ +Name,Lat,Lon,Address,Category +Boston,42.3601,-71.0589,nope,health +Olin College,42.2926,-71.2644,"1000 Olin Way, Needham, MA 02492",support \ No newline at end of file diff --git a/test_csv_import.py b/test_csv_import.py new file mode 100644 index 0000000..6ee42df --- /dev/null +++ b/test_csv_import.py @@ -0,0 +1,7 @@ +import csv +listlist = [] +with open('test.csv', 'rb') as csvfile: + spamreader = csv.reader(csvfile) + for row in spamreader: + listlist.append(row) +print listlist From 643aca055fc8142e9b51a9c4c835c7026698f6fd Mon Sep 17 00:00:00 2001 From: nielsenlouise Date: Thu, 10 Mar 2016 00:01:23 -0500 Subject: [PATCH 08/16] things modified in search of buttons and legends --- model_pandas.py | 23 ++++++++-- model_pandas.pyc | Bin 1847 -> 2298 bytes plot | 28 ++++++++++++ resources_plot.html | 6 +-- test.csv | 12 ++++- test_bokeh_data.csv | 3 -- test_csv_import.py | 7 --- test_server.py | 106 ++++++++++++++++++++++++++++++++++++++++++++ view_pandas.py | 38 ++++++++++++++-- 9 files changed, 200 insertions(+), 23 deletions(-) create mode 100644 plot delete mode 100644 test_bokeh_data.csv delete mode 100644 test_csv_import.py create mode 100644 test_server.py diff --git a/model_pandas.py b/model_pandas.py index 0301806..8f8b062 100644 --- a/model_pandas.py +++ b/model_pandas.py @@ -1,7 +1,7 @@ """This file contains the model class using the pandas library (hooray!) """ -import pandas +from pandas import * from bokeh.plotting import ColumnDataSource as plotColumnDataSource @@ -9,16 +9,21 @@ class Model(object): """A Model() object contains a pandas.DataFrame of resources. """ - def __init__(self, source, filename='test.csv', frame=None): + def __init__(self, source=None, filename='test.csv', frame=None): self.source = source self.filename = filename if frame is None: - self.frame = pandas.DataFrame(pandas.read_csv(self.filename)) + self.frame = DataFrame(read_csv(self.filename)) else: self.frame = frame def set_color_stuff(self): - colormap = {'health': 'blue', 'support': 'green'} + colormap = {'health': 'red', + 'support': 'green', + 'housing': 'blue', + 'advocacy': 'purple', + 'legal': 'cyan' + } self.frame['color'] = self.frame['Category'].map(lambda x: colormap[x]) self.source = plotColumnDataSource(dict( name=self.frame['Name'], @@ -27,3 +32,13 @@ def set_color_stuff(self): address=self.frame['Address'], category=self.frame['Category'], color=self.frame['color'])) + + def update_model(self): + """This is going to update the model, probably has to filter things. + """ + pass + +if __name__ == '__main__': + thing = Model() + thing.set_color_stuff + print thing.frame diff --git a/model_pandas.pyc b/model_pandas.pyc index 4318d5bc7d458e8f61d0990f9c34430a647efebb..6d74a5877ac9a103606becbe651af267d5aaf871 100644 GIT binary patch delta 955 zcmX|9OKa3n6h1eZJSNjlr=zx=7Bq_1P}(9D3WDGZR9ws=Q(P1!WG0zMCryUQ9bur* zMT-wy)$IKR3W^JH>o4#p_!9(O34-6rbeiOT_k8!Bd(L;x&DZkZ`AzlrtY!cE`Lso+ zkBa#&M(P6sqFtb%K%q#`&dH6{jnJS#r@lhN=M?I61Q(M+llF=vc(Ulx;~0kwYB=V} zvqs4gh$I=-PCjkiE5Nvqk!}G(oJMq@LV=cN0xEQ@(r$qQm5#B6l|pXl-+7on?f3Q7`;vyZWybc@T8@Y%&4*w9>-YGXrT&BxXTr>NuC)r1( zcDSOnSS61+40cJs0D2Q)3T;CWq-?WN9TPfXVk%N#(e@k4WuWpB)u84TQ5&Vr&`V-v zED?LNbXzK{Iw((<=BO4_Kz4J7d9dnq>m11WDY*c$FeS)=SZ6_NN2E`ZcxW5fy9nWR zJtb<5{a9)+qOjvf z*$4HzSjm#Yd!c4!ZAmOi!Kk-wI*DvDzE>^*BLH}(NW%E9qdH5`T6 z6TnWlm)iI`2}Id4u}6czm!U1Yp}n63VYF@!hDp|s|?q(U)tc1UAQSJgRbaG z)ht%>HhJE@--|u3?v&Vl4KV4X9|wLa%iztVA9gnfQ6eQua=CVw6X$+Ob1!U3mlL=w jH}5hkfn%PZ6FS)+t)HzJ)hdV66-!jqh08N&ts(vcM60Ug delta 603 zcmX|7Jx?1!5S`h(+dF>|oJ7DiQ2=2b;wwc$g#=1XT%4sSvV@S$8G>!u7QS?D5GYZk zG}iR|jntI+1!*E#N}mGJQRU4Ub9ei0-psz)xARc`Irql7FXeasPClN{^vg6AdSI3jBcdB@=iVC0w1-1iCrgK$#ZK#gGp=;zliffT4 zANcgsAp|3)5z#RMlLerT>N^2l>{IGc+s)9^YMbdQ`&447m($JD7?N7VXjqMW@yuG@ zA|5n)Nnkvf<(m6o0-)Vi`9(4O@dfq#Wk)imN7FE`7wp%A@ U%xKuhD6RYnirK`iDe}DYA42+NzW@LL diff --git a/plot b/plot new file mode 100644 index 0000000..fdf886d --- /dev/null +++ b/plot @@ -0,0 +1,28 @@ + + + + + + Bokeh Plot + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/resources_plot.html b/resources_plot.html index 2864366..d5629f9 100644 --- a/resources_plot.html +++ b/resources_plot.html @@ -14,12 +14,12 @@ -
+