Skip to content

Instantly share code, notes, and snippets.

@AndradeEduardo
Created April 19, 2018 12:09
Show Gist options
  • Save AndradeEduardo/7055049b6864662598f673755b72d8ee to your computer and use it in GitHub Desktop.
Save AndradeEduardo/7055049b6864662598f673755b72d8ee to your computer and use it in GitHub Desktop.
Gist that shows on the map the risk related with personnel expenses for some Brazilian states.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from bokeh.io import show, output_notebook, output_file\n",
"from bokeh.models import (GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d,\n",
" PanTool, WheelZoomTool, BoxSelectTool, Range1d, Slider, CustomJS)\n",
"\n",
"from bokeh.layouts import widgetbox, row"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Column headings:\n",
"Index(['Year', 'PersonnelExpenses', 'NetCurrentIncome', 'State', 'AlertLimit',\n",
" 'PrudentialLimit', 'MaxLimit', 'Lat', 'Long'],\n",
" dtype='object')\n"
]
}
],
"source": [
"df = pd.read_excel('BR_States_PersonelCosts.xlsx', sheet_name='PersonnelExpenses')\n",
"print(\"Column headings:\")\n",
"print(df.columns)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A new column named 'Limit' is created to contain the color according to the risk level of reaching the threshold. These limits are established by the Brazilian Fiscal Responsibility Law"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# df['color'] = np.where(df['Set']=='Z', 'green', 'red')\n",
"df['Limit'] = np.where((df['PersonnelExpenses']/df['NetCurrentIncome']*100) > 44.10,\n",
" 'yellow', 'blue')\n",
"df['Limit'] = np.where((df['PersonnelExpenses']/df['NetCurrentIncome']*100) > 46.55,\n",
" 'orange', df['Limit'])\n",
"df['Limit'] = np.where((df['PersonnelExpenses']/df['NetCurrentIncome']*100) > 49,\n",
" 'red', df['Limit'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Defining the GoogleMaps coordinates to have Brazil in the center and creating a plot of a map."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"map_options = GMapOptions(lat=-13, lng=-52, zoom=4)\n",
"API_KEY = os.environ['GMAPS_API_KEY']\n",
"plot = GMapPlot(x_range=Range1d(),\n",
" y_range=Range1d(),\n",
" map_options=map_options,\n",
" api_key=API_KEY)\n",
"\n",
"plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Creating a list of source data as ColumnDataSource objects. Each data source has the information for all the states of the personnel expenses / net income ratio for each year. The 'rad' information is the size of the circle to be ploted. It is bigger as it approaches to 1 and represents how close the personnel expenses are to the net income."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"source_list = list()\n",
"years = df['Year'].unique()\n",
"years.sort()\n",
"\n",
"for year in years:\n",
" source = ColumnDataSource(data=dict(lat = df.loc[df['Year'] == year]['Lat'].tolist(),\n",
" lon = df.loc[df['Year'] == year]['Long'].tolist(),\n",
" col = df.loc[df['Year'] == year]['Limit'].tolist(),\n",
" rad = ((df.loc[df['Year'] == year]['PersonnelExpenses']/\n",
" df.loc[df['Year'] == year]['NetCurrentIncome']*40)**1.2).tolist()))\n",
" source_list.append(source)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A Circle object is created. Its attributes are mapped to the data source previously created that refers to the last year."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.renderers.GlyphRenderer\">GlyphRenderer</b>(</div><div style=\"display: table-cell;\">id&nbsp;=&nbsp;'4ee1ec24-c0c9-4657-8df8-f780ee6f93c4', <span id=\"dbb7f906-8ac4-48b8-b130-dc6111c82e02\" style=\"cursor: pointer;\">&hellip;)</span></div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">data_source&nbsp;=&nbsp;ColumnDataSource(id='b0b52829-b8b4-4840-b147-cc4e6e165b2c', ...),</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">glyph&nbsp;=&nbsp;Circle(id='1816f5ae-7cfd-48ab-902f-c76c0b940a56', ...),</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">hover_glyph&nbsp;=&nbsp;None,</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">level&nbsp;=&nbsp;'glyph',</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">muted&nbsp;=&nbsp;False,</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">muted_glyph&nbsp;=&nbsp;None,</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name&nbsp;=&nbsp;None,</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">nonselection_glyph&nbsp;=&nbsp;'auto',</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">selection_glyph&nbsp;=&nbsp;'auto',</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events&nbsp;=&nbsp;[],</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags&nbsp;=&nbsp;[],</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">view&nbsp;=&nbsp;CDSView(id='85a894ca-56c6-4c6b-82b2-e2bb6a23dcdb', ...),</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible&nbsp;=&nbsp;True,</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">x_range_name&nbsp;=&nbsp;'default',</div></div><div class=\"889f1bf1-be87-4a06-955e-defeb95bacb2\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">y_range_name&nbsp;=&nbsp;'default')</div></div></div>\n",
"<script>\n",
"(function() {\n",
" var expanded = false;\n",
" var ellipsis = document.getElementById(\"dbb7f906-8ac4-48b8-b130-dc6111c82e02\");\n",
" ellipsis.addEventListener(\"click\", function() {\n",
" var rows = document.getElementsByClassName(\"889f1bf1-be87-4a06-955e-defeb95bacb2\");\n",
" for (var i = 0; i < rows.length; i++) {\n",
" var el = rows[i];\n",
" el.style.display = expanded ? \"none\" : \"table-row\";\n",
" }\n",
" ellipsis.innerHTML = expanded ? \"&hellip;)\" : \"&lsaquo;&lsaquo;&lsaquo;\";\n",
" expanded = !expanded;\n",
" });\n",
"})();\n",
"</script>\n"
],
"text/plain": [
"GlyphRenderer(id='4ee1ec24-c0c9-4657-8df8-f780ee6f93c4', ...)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"circle = Circle(x='lon',\n",
" y='lat',\n",
" size='rad',\n",
" fill_color='col',\n",
" fill_alpha=0.5)\n",
"\n",
"plot.add_glyph(source_list[len(source_list)-1], circle)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The slider is created. It is alos set to the last year. The callback function \"callback\" is defined. It receives the slider value each time it is moved. The min_year varible is used to correctly derefer to the correct position of the source list. However, the image is not updates."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"min_year = df['Year'].min()\n",
"max_year = df['Year'].max()\n",
"year_slider = min_year\n",
"\n",
"callback = CustomJS(args=dict(source=source_list[year_slider-min_year]), code=\"\"\"\n",
" var data = source.data;\n",
" source.change.emit();\n",
"\"\"\")\n",
"year_slider = Slider(start=min_year, end=max_year,\n",
" value=max_year, step=1,\n",
" title=\"Year\", callback=callback)\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"layout = row(\n",
" plot,\n",
" widgetbox(year_slider),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div class=\"bk-root\">\n",
" <a href=\"https://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
" <span id=\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\">Loading BokehJS ...</span>\n",
" </div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function(root) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
"\n",
" var force = true;\n",
"\n",
" if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
" root._bokeh_onload_callbacks = [];\n",
" root._bokeh_is_loading = undefined;\n",
" }\n",
"\n",
" var JS_MIME_TYPE = 'application/javascript';\n",
" var HTML_MIME_TYPE = 'text/html';\n",
" var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
" var CLASS_NAME = 'output_bokeh rendered_html';\n",
"\n",
" /**\n",
" * Render data to the DOM node\n",
" */\n",
" function render(props, node) {\n",
" var script = document.createElement(\"script\");\n",
" node.appendChild(script);\n",
" }\n",
"\n",
" /**\n",
" * Handle when an output is cleared or removed\n",
" */\n",
" function handleClearOutput(event, handle) {\n",
" var cell = handle.cell;\n",
"\n",
" var id = cell.output_area._bokeh_element_id;\n",
" var server_id = cell.output_area._bokeh_server_id;\n",
" // Clean up Bokeh references\n",
" if (id !== undefined) {\n",
" Bokeh.index[id].model.document.clear();\n",
" delete Bokeh.index[id];\n",
" }\n",
"\n",
" if (server_id !== undefined) {\n",
" // Clean up Bokeh references\n",
" var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
" cell.notebook.kernel.execute(cmd, {\n",
" iopub: {\n",
" output: function(msg) {\n",
" var element_id = msg.content.text.trim();\n",
" Bokeh.index[element_id].model.document.clear();\n",
" delete Bokeh.index[element_id];\n",
" }\n",
" }\n",
" });\n",
" // Destroy server and session\n",
" var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
" cell.notebook.kernel.execute(cmd);\n",
" }\n",
" }\n",
"\n",
" /**\n",
" * Handle when a new output is added\n",
" */\n",
" function handleAddOutput(event, handle) {\n",
" var output_area = handle.output_area;\n",
" var output = handle.output;\n",
"\n",
" // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
" if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
" return\n",
" }\n",
"\n",
" var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
"\n",
" if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
" toinsert[0].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
" // store reference to embed id on output_area\n",
" output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
" }\n",
" if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
" var bk_div = document.createElement(\"div\");\n",
" bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
" var script_attrs = bk_div.children[0].attributes;\n",
" for (var i = 0; i < script_attrs.length; i++) {\n",
" toinsert[0].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
" }\n",
" // store reference to server id on output_area\n",
" output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
" }\n",
" }\n",
"\n",
" function register_renderer(events, OutputArea) {\n",
"\n",
" function append_mime(data, metadata, element) {\n",
" // create a DOM node to render to\n",
" var toinsert = this.create_output_subarea(\n",
" metadata,\n",
" CLASS_NAME,\n",
" EXEC_MIME_TYPE\n",
" );\n",
" this.keyboard_manager.register_events(toinsert);\n",
" // Render to node\n",
" var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
" render(props, toinsert[0]);\n",
" element.append(toinsert);\n",
" return toinsert\n",
" }\n",
"\n",
" /* Handle when an output is cleared or removed */\n",
" events.on('clear_output.CodeCell', handleClearOutput);\n",
" events.on('delete.Cell', handleClearOutput);\n",
"\n",
" /* Handle when a new output is added */\n",
" events.on('output_added.OutputArea', handleAddOutput);\n",
"\n",
" /**\n",
" * Register the mime type and append_mime function with output_area\n",
" */\n",
" OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
" /* Is output safe? */\n",
" safe: true,\n",
" /* Index of renderer in `output_area.display_order` */\n",
" index: 0\n",
" });\n",
" }\n",
"\n",
" // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
" if (root.Jupyter !== undefined) {\n",
" var events = require('base/js/events');\n",
" var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
"\n",
" if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
" register_renderer(events, OutputArea);\n",
" }\n",
" }\n",
"\n",
" \n",
" if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
" root._bokeh_timeout = Date.now() + 5000;\n",
" root._bokeh_failed_load = false;\n",
" }\n",
"\n",
" var NB_LOAD_WARNING = {'data': {'text/html':\n",
" \"<div style='background-color: #fdd'>\\n\"+\n",
" \"<p>\\n\"+\n",
" \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
" \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
" \"</p>\\n\"+\n",
" \"<ul>\\n\"+\n",
" \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
" \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
" \"</ul>\\n\"+\n",
" \"<code>\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"</code>\\n\"+\n",
" \"</div>\"}};\n",
"\n",
" function display_loaded() {\n",
" var el = document.getElementById(\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\");\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS is loading...\";\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
" }\n",
" } else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(display_loaded, 100)\n",
" }\n",
" }\n",
"\n",
"\n",
" function run_callbacks() {\n",
" try {\n",
" root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
" }\n",
" finally {\n",
" delete root._bokeh_onload_callbacks\n",
" }\n",
" console.info(\"Bokeh: all callbacks have finished\");\n",
" }\n",
"\n",
" function load_libs(js_urls, callback) {\n",
" root._bokeh_onload_callbacks.push(callback);\n",
" if (root._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",
" root._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",
" root._bokeh_is_loading--;\n",
" if (root._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",
" };var element = document.getElementById(\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\");\n",
" if (element == null) {\n",
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid '1a17a53e-ee40-44e3-bdf9-764241e2fd6b' but no matching script tag was found. \")\n",
" return false;\n",
" }\n",
"\n",
" var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.14.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.14.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.14.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.14.min.js\"];\n",
"\n",
" var inline_js = [\n",
" function(Bokeh) {\n",
" Bokeh.set_log_level(\"info\");\n",
" },\n",
" \n",
" function(Bokeh) {\n",
" \n",
" },\n",
" function(Bokeh) {\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.14.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.14.min.css\");\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.14.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.14.min.css\");\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.14.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.14.min.css\");\n",
" }\n",
" ];\n",
"\n",
" function run_inline_js() {\n",
" \n",
" if ((root.Bokeh !== undefined) || (force === true)) {\n",
" for (var i = 0; i < inline_js.length; i++) {\n",
" inline_js[i].call(root, root.Bokeh);\n",
" }if (force === true) {\n",
" display_loaded();\n",
" }} else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(run_inline_js, 100);\n",
" } else if (!root._bokeh_failed_load) {\n",
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
" root._bokeh_failed_load = true;\n",
" } else if (force !== true) {\n",
" var cell = $(document.getElementById(\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\")).parents('.cell').data().cell;\n",
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
" }\n",
"\n",
" }\n",
"\n",
" if (root._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",
"}(window));"
],
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n }\n finally {\n delete root._bokeh_onload_callbacks\n }\n console.info(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(js_urls, callback) {\n root._bokeh_onload_callbacks.push(callback);\n if (root._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 root._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 root._bokeh_is_loading--;\n if (root._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 };var element = document.getElementById(\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\");\n if (element == null) {\n console.log(\"Bokeh: ERROR: autoload.js configured with elementid '1a17a53e-ee40-44e3-bdf9-764241e2fd6b' but no matching script tag was found. \")\n return false;\n }\n\n var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.14.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.14.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.14.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.14.min.js\"];\n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n \n function(Bokeh) {\n \n },\n function(Bokeh) {\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.14.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.14.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.14.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.14.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.14.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.14.min.css\");\n }\n ];\n\n function run_inline_js() {\n \n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"1a17a53e-ee40-44e3-bdf9-764241e2fd6b\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._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}(window));"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"output_notebook()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/EduardoAndrade/anaconda/lib/python3.6/site-packages/bokeh/core/json_encoder.py:80: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" elif np.issubdtype(type(obj), np.float):\n"
]
},
{
"data": {
"text/html": [
"\n",
"<div class=\"bk-root\">\n",
" <div class=\"bk-plotdiv\" id=\"a0a3a931-8702-42de-bea5-e7d3a93c0312\"></div>\n",
"</div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"d9340c99-6f80-43e1-b863-8de844da6cb1\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"109951d6-4e82-43c4-aa9c-93295d1213ec\",\"type\":\"GMapPlot\"},{\"id\":\"68a9e9d3-34e7-4983-bf31-49268715e159\",\"type\":\"WidgetBox\"}]},\"id\":\"5598b5f6-6e9b-4e44-b90b-743c32630648\",\"type\":\"Row\"},{\"attributes\":{\"callback\":null},\"id\":\"b87adcb5-4b91-430f-83f2-59f03f51c726\",\"type\":\"Range1d\"},{\"attributes\":{\"children\":[{\"id\":\"21008840-eaca-4c19-9222-5c35f748a3ae\",\"type\":\"Slider\"}]},\"id\":\"68a9e9d3-34e7-4983-bf31-49268715e159\",\"type\":\"WidgetBox\"},{\"attributes\":{\"callback\":{\"id\":\"474f68d7-5d39-4b6e-879e-7e0ec4dd81e6\",\"type\":\"CustomJS\"},\"end\":2017,\"start\":2002,\"title\":\"Year\",\"value\":2017},\"id\":\"21008840-eaca-4c19-9222-5c35f748a3ae\",\"type\":\"Slider\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"0960d921-1c19-4224-9843-a01ae4802541\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"b0b52829-b8b4-4840-b147-cc4e6e165b2c\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1816f5ae-7cfd-48ab-902f-c76c0b940a56\",\"type\":\"Circle\"},\"hover_glyph\":null,\"muted_glyph\":null,\"view\":{\"id\":\"85a894ca-56c6-4c6b-82b2-e2bb6a23dcdb\",\"type\":\"CDSView\"}},\"id\":\"4ee1ec24-c0c9-4657-8df8-f780ee6f93c4\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"field\":\"col\"},\"size\":{\"field\":\"rad\",\"units\":\"screen\"},\"x\":{\"field\":\"lon\"},\"y\":{\"field\":\"lat\"}},\"id\":\"1816f5ae-7cfd-48ab-902f-c76c0b940a56\",\"type\":\"Circle\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"lat\",\"lon\",\"col\",\"rad\"],\"data\":{\"col\":[\"orange\",\"blue\",\"blue\",\"red\",\"red\",\"yellow\"],\"lat\":[-22.84,-3.07,-3.71,-8.28,-27.33,-24.89],\"lon\":[-43.15,-61.66,-38.54,-35.07,-49.44,-51.55],\"rad\":[33.4792230241081,28.12761750481825,\"NaN\",41.35243665370328,35.91818766201632,31.687306223447983]}},\"id\":\"bc6577f7-3ba5-44d2-ba76-12d7df38c829\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"d88ef33e-7b98-482b-95c2-c2910cce0dad\",\"type\":\"PanTool\"},{\"id\":\"5516e490-9bd4-45f6-95b6-a1285dea39e7\",\"type\":\"WheelZoomTool\"},{\"id\":\"bf768a4a-2575-4cab-af0d-fdd56d7b534b\",\"type\":\"BoxSelectTool\"}]},\"id\":\"9425c933-996d-48a2-970c-2a6b7391a9a3\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"b0b52829-b8b4-4840-b147-cc4e6e165b2c\",\"type\":\"ColumnDataSource\"}},\"id\":\"85a894ca-56c6-4c6b-82b2-e2bb6a23dcdb\",\"type\":\"CDSView\"},{\"attributes\":{\"plot\":null,\"text\":\"\"},\"id\":\"3698beac-3f3f-435e-b66f-78f153bf3b6f\",\"type\":\"Title\"},{\"attributes\":{\"api_key\":\"AIzaSyDGgHr8moKTmLLWvD0OyrJp0DosAKn59RE\",\"map_options\":{\"id\":\"1f10f1eb-5206-43da-a6cd-d0180bd9bd57\",\"type\":\"GMapOptions\"},\"renderers\":[{\"id\":\"0960d921-1c19-4224-9843-a01ae4802541\",\"type\":\"BoxAnnotation\"},{\"id\":\"4ee1ec24-c0c9-4657-8df8-f780ee6f93c4\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"3698beac-3f3f-435e-b66f-78f153bf3b6f\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"9425c933-996d-48a2-970c-2a6b7391a9a3\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"096dc919-cabb-4598-a3b0-9a28d2b9d36b\",\"type\":\"Range1d\"},\"x_scale\":{\"id\":\"bd97369b-7235-4987-927c-d6be17d33a40\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"b87adcb5-4b91-430f-83f2-59f03f51c726\",\"type\":\"Range1d\"},\"y_scale\":{\"id\":\"de06b7e8-acf2-446d-9f11-eac1d3cdc333\",\"type\":\"LinearScale\"}},\"id\":\"109951d6-4e82-43c4-aa9c-93295d1213ec\",\"type\":\"GMapPlot\"},{\"attributes\":{\"callback\":null},\"id\":\"096dc919-cabb-4598-a3b0-9a28d2b9d36b\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"de06b7e8-acf2-446d-9f11-eac1d3cdc333\",\"type\":\"LinearScale\"},{\"attributes\":{\"args\":{\"source\":{\"id\":\"bc6577f7-3ba5-44d2-ba76-12d7df38c829\",\"type\":\"ColumnDataSource\"}},\"code\":\"\\n var data = source.data;\\n source.change.emit();\\n\"},\"id\":\"474f68d7-5d39-4b6e-879e-7e0ec4dd81e6\",\"type\":\"CustomJS\"},{\"attributes\":{},\"id\":\"d88ef33e-7b98-482b-95c2-c2910cce0dad\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"bd97369b-7235-4987-927c-d6be17d33a40\",\"type\":\"LinearScale\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"lat\",\"lon\",\"col\",\"rad\"],\"data\":{\"col\":[\"red\",\"orange\",\"blue\",\"orange\",\"red\",\"yellow\",\"red\",\"yellow\"],\"lat\":[-22.84,-3.07,-3.71,-8.28,1.89,-30.01,-27.33,-24.89],\"lon\":[-43.15,-61.66,-38.54,-35.07,-61.22,-51.22,-49.44,-51.55],\"rad\":[51.74545961820778,34.547818388247194,29.89504841453372,35.50948669368608,36.14539203670606,33.41059258438293,36.16797500727658,32.20169670714397]}},\"id\":\"b0b52829-b8b4-4840-b147-cc4e6e165b2c\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"lat\":-13,\"lng\":-52,\"zoom\":4},\"id\":\"1f10f1eb-5206-43da-a6cd-d0180bd9bd57\",\"type\":\"GMapOptions\"},{\"attributes\":{\"callback\":null,\"overlay\":{\"id\":\"0960d921-1c19-4224-9843-a01ae4802541\",\"type\":\"BoxAnnotation\"}},\"id\":\"bf768a4a-2575-4cab-af0d-fdd56d7b534b\",\"type\":\"BoxSelectTool\"},{\"attributes\":{},\"id\":\"5516e490-9bd4-45f6-95b6-a1285dea39e7\",\"type\":\"WheelZoomTool\"}],\"root_ids\":[\"5598b5f6-6e9b-4e44-b90b-743c32630648\"]},\"title\":\"Bokeh Application\",\"version\":\"0.12.14\"}};\n",
" var render_items = [{\"docid\":\"d9340c99-6f80-43e1-b863-8de844da6cb1\",\"elementid\":\"a0a3a931-8702-42de-bea5-e7d3a93c0312\",\"modelid\":\"5598b5f6-6e9b-4e44-b90b-743c32630648\"}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" clearInterval(timer);\n",
" }\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\")\n",
" clearInterval(timer);\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "5598b5f6-6e9b-4e44-b90b-743c32630648"
}
},
"output_type": "display_data"
}
],
"source": [
"show(layout)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment