Skip to content

Instantly share code, notes, and snippets.

@aiguofer
Created January 27, 2017 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aiguofer/927e9d71f6e1e8ea48ade18056ab3322 to your computer and use it in GitHub Desktop.
Save aiguofer/927e9d71f6e1e8ea48ade18056ab3322 to your computer and use it in GitHub Desktop.
Bokeh 2 bar width
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2017-01-27T21:46:59.218246",
"start_time": "2017-01-27T21:46:58.388425"
},
"collapsed": false,
"extensions": {
"jupyter_dashboards": {
"version": 1,
"views": {
"grid_default": {
"col": 0,
"height": 4,
"hidden": true,
"row": 4,
"width": 4
},
"report_default": {
"hidden": false
}
}
}
},
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div class=\"bk-root\">\n",
" <a href=\"http://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
" <span id=\"dbc060e4-0467-4dda-9793-b9b1b3fff464\">Loading BokehJS ...</span>\n",
" </div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function(global) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
"\n",
" var force = true;\n",
"\n",
" if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
" window._bokeh_onload_callbacks = [];\n",
" window._bokeh_is_loading = undefined;\n",
" }\n",
"\n",
"\n",
" \n",
" if (typeof (window._bokeh_timeout) === \"undefined\" || force === true) {\n",
" window._bokeh_timeout = Date.now() + 5000;\n",
" window._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",
" if (window.Bokeh !== undefined) {\n",
" document.getElementById(\"dbc060e4-0467-4dda-9793-b9b1b3fff464\").textContent = \"BokehJS successfully loaded.\";\n",
" } else if (Date.now() < window._bokeh_timeout) {\n",
" setTimeout(display_loaded, 100)\n",
" }\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",
" };var element = document.getElementById(\"dbc060e4-0467-4dda-9793-b9b1b3fff464\");\n",
" if (element == null) {\n",
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid 'dbc060e4-0467-4dda-9793-b9b1b3fff464' 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.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.4.min.js\"];\n",
"\n",
" var inline_js = [\n",
" function(Bokeh) {\n",
" Bokeh.set_log_level(\"info\");\n",
" },\n",
" \n",
" function(Bokeh) {\n",
" \n",
" document.getElementById(\"dbc060e4-0467-4dda-9793-b9b1b3fff464\").textContent = \"BokehJS is loading...\";\n",
" },\n",
" function(Bokeh) {\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.4.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.4.min.css\");\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.4.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.4.min.css\");\n",
" }\n",
" ];\n",
"\n",
" function run_inline_js() {\n",
" \n",
" if ((window.Bokeh !== undefined) || (force === true)) {\n",
" for (var i = 0; i < inline_js.length; i++) {\n",
" inline_js[i](window.Bokeh);\n",
" }if (force === true) {\n",
" display_loaded();\n",
" }} else if (Date.now() < window._bokeh_timeout) {\n",
" setTimeout(run_inline_js, 100);\n",
" } else if (!window._bokeh_failed_load) {\n",
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
" window._bokeh_failed_load = true;\n",
" } else if (force !== true) {\n",
" var cell = $(document.getElementById(\"dbc060e4-0467-4dda-9793-b9b1b3fff464\")).parents('.cell').data().cell;\n",
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
" }\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": [
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from bokeh.plotting import figure, show\n",
"from bokeh.io import output_notebook, push_notebook\n",
"from bokeh.layouts import layout\n",
"from bokeh.models import ColumnDataSource, CustomJS, DataRange1d, LinearAxis, Range1d, DateFormatter\n",
"from bokeh.models.widgets import DataTable, TableColumn\n",
"\n",
"from ipywidgets import interact\n",
"\n",
"output_notebook()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2017-01-27T21:46:59.297771",
"start_time": "2017-01-27T21:46:59.221792"
},
"collapsed": true,
"extensions": {
"jupyter_dashboards": {
"version": 1,
"views": {
"grid_default": {
"hidden": true
},
"report_default": {
"hidden": false
}
}
}
}
},
"outputs": [],
"source": [
"ix = pd.date_range('2016-01-01', '2017-01-01', freq='d', name='date')\n",
"srs = pd.Series(np.random.randint(0, 300, size=len(ix)), index=ix, name='volume')\n",
"srs2 = pd.Series(np.random.randint(0, 1000, size=len(ix)), index=ix, name='size')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2017-01-27T21:46:59.592865",
"start_time": "2017-01-27T21:46:59.301441"
},
"collapsed": false,
"extensions": {
"jupyter_dashboards": {
"version": 1,
"views": {
"grid_default": {
"col": 0,
"height": 14,
"hidden": false,
"row": 2,
"width": 6
},
"report_default": {
"hidden": false
}
}
}
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" <div class=\"bk-root\">\n",
" <div class=\"bk-plotdiv\" id=\"e095a58d-479f-494f-a4ed-8c12d5d31f2b\"></div>\n",
" </div>\n",
"<script type=\"text/javascript\">\n",
" \n",
" (function(global) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
" \n",
" var force = false;\n",
" \n",
" if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
" window._bokeh_onload_callbacks = [];\n",
" window._bokeh_is_loading = undefined;\n",
" }\n",
" \n",
" \n",
" \n",
" if (typeof (window._bokeh_timeout) === \"undefined\" || force === true) {\n",
" window._bokeh_timeout = Date.now() + 0;\n",
" window._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",
" if (window.Bokeh !== undefined) {\n",
" document.getElementById(\"e095a58d-479f-494f-a4ed-8c12d5d31f2b\").textContent = \"BokehJS successfully loaded.\";\n",
" } else if (Date.now() < window._bokeh_timeout) {\n",
" setTimeout(display_loaded, 100)\n",
" }\n",
" }if ((window.Jupyter !== undefined) && Jupyter.notebook.kernel) {\n",
" comm_manager = Jupyter.notebook.kernel.comm_manager\n",
" comm_manager.register_target(\"bbd2ee72-8aaf-4558-be28-e3765dc85abb\", function () {});\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",
" };var element = document.getElementById(\"e095a58d-479f-494f-a4ed-8c12d5d31f2b\");\n",
" if (element == null) {\n",
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid 'e095a58d-479f-494f-a4ed-8c12d5d31f2b' but no matching script tag was found. \")\n",
" return false;\n",
" }\n",
" \n",
" var js_urls = [];\n",
" \n",
" var inline_js = [\n",
" function(Bokeh) {\n",
" (function() {\n",
" var fn = function() {\n",
" var docs_json = {\"d2f5e816-9498-4acf-9e87-256e2a8fe471\":{\"roots\":{\"references\":[{\"attributes\":{\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"a3876c01-dc50-4a6a-bf31-6f2b51776a9e\",\"type\":\"PanTool\"},{\"attributes\":{\"base\":24,\"mantissas\":[1,2,4,6,8,12],\"max_interval\":43200000.0,\"min_interval\":3600000.0,\"num_minor_ticks\":0},\"id\":\"10e20b50-044b-4f4d-8864-8f3667f9a45f\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"a3876c01-dc50-4a6a-bf31-6f2b51776a9e\",\"type\":\"PanTool\"},{\"id\":\"9504cbcf-004a-4187-bcaf-eda5e75850fd\",\"type\":\"WheelZoomTool\"},{\"id\":\"788f1fa3-973a-4e0c-9bfb-9bb4321b6372\",\"type\":\"BoxZoomTool\"},{\"id\":\"8a72e1f4-6e8b-4db6-ae51-1fe070611b83\",\"type\":\"SaveTool\"},{\"id\":\"58ffd6f3-5603-41f9-a541-79bdbafae613\",\"type\":\"ResetTool\"},{\"id\":\"4b72c0c3-f85b-44e1-9404-41b05883c5f5\",\"type\":\"HelpTool\"}]},\"id\":\"eb5af0f4-26a9-4023-8e65-dcdff1c6cbd1\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"volume\"},\"width\":{\"value\":1945993846.1538465},\"x\":{\"field\":\"date\"}},\"id\":\"3a98df8e-7e51-4963-99c8-41fa1373a482\",\"type\":\"VBar\"},{\"attributes\":{\"below\":[{\"id\":\"5051d3d4-cb47-4d12-ad5e-af1d579e834d\",\"type\":\"DatetimeAxis\"}],\"extra_y_ranges\":{\"size\":{\"id\":\"afe072da-9289-49e5-9210-6561f021d3e0\",\"type\":\"Range1d\"}},\"left\":[{\"id\":\"94f23229-39d4-49ad-a62c-0bb78c5f2b51\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"plot_width\":550,\"renderers\":[{\"id\":\"5051d3d4-cb47-4d12-ad5e-af1d579e834d\",\"type\":\"DatetimeAxis\"},{\"id\":\"8b45a63c-dd42-4b43-8dd9-8c0d9faa23d6\",\"type\":\"Grid\"},{\"id\":\"94f23229-39d4-49ad-a62c-0bb78c5f2b51\",\"type\":\"LinearAxis\"},{\"id\":\"54118f61-cd87-426a-93d2-63d7af5080e0\",\"type\":\"Grid\"},{\"id\":\"34820e0f-de6e-4776-96b6-44e63817056a\",\"type\":\"BoxAnnotation\"},{\"id\":\"407ed82e-58c5-4067-8263-acbd5ef2240e\",\"type\":\"LinearAxis\"},{\"id\":\"3ca6343c-6450-4dc9-b2b5-4126013b084c\",\"type\":\"GlyphRenderer\"},{\"id\":\"419506ef-b027-4218-8320-58d4894c80e1\",\"type\":\"GlyphRenderer\"},{\"id\":\"1d1b8a1a-eb02-458a-8729-efc94380a602\",\"type\":\"GlyphRenderer\"}],\"right\":[{\"id\":\"407ed82e-58c5-4067-8263-acbd5ef2240e\",\"type\":\"LinearAxis\"}],\"title\":{\"id\":\"021cc22f-b301-4c10-9806-f6ea441bce51\",\"type\":\"Title\"},\"tool_events\":{\"id\":\"ce5ba02b-7d25-4296-8da1-d33d3bcc0c6f\",\"type\":\"ToolEvents\"},\"toolbar\":{\"id\":\"eb5af0f4-26a9-4023-8e65-dcdff1c6cbd1\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"a69ada92-9041-4825-a8b4-a0a44c200928\",\"type\":\"DataRange1d\"},\"y_range\":{\"id\":\"11c87eb0-d97a-4628-89ff-66c4f37311ae\",\"type\":\"Range1d\"}},\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"volume\"},\"width\":{\"value\":1945993846.1538465},\"x\":{\"field\":\"date\"}},\"id\":\"02cbb28e-47d9-46dd-b59a-18fcb10082c1\",\"type\":\"VBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"volume\"},\"width\":{\"value\":1945993846.1538465},\"x\":{\"field\":\"date\"}},\"id\":\"702b7cf7-3d74-4db6-8ff0-6d379994634a\",\"type\":\"VBar\"},{\"attributes\":{\"dimensions\":\"width\",\"overlay\":{\"id\":\"34820e0f-de6e-4776-96b6-44e63817056a\",\"type\":\"BoxAnnotation\"},\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"788f1fa3-973a-4e0c-9bfb-9bb4321b6372\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"formatter\":{\"id\":\"8260983d-3280-46e6-80d4-2031abc63faf\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"418dddcf-3b30-43be-8c03-c5daf88124bc\",\"type\":\"BasicTicker\"}},\"id\":\"94f23229-39d4-49ad-a62c-0bb78c5f2b51\",\"type\":\"LinearAxis\"},{\"attributes\":{\"days\":[1,15]},\"id\":\"f4ad7a69-dcf4-47e9-994a-15019fcbc56c\",\"type\":\"DaysTicker\"},{\"attributes\":{\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"4b72c0c3-f85b-44e1-9404-41b05883c5f5\",\"type\":\"HelpTool\"},{\"attributes\":{\"months\":[0,2,4,6,8,10]},\"id\":\"2261f2f4-1ede-416c-b258-3fdea02b7793\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"num_minor_ticks\":5},\"id\":\"658c072f-29eb-4c23-887c-6dfb9aa77cd6\",\"type\":\"DatetimeTicker\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"date\"},\"y\":{\"field\":\"size\"}},\"id\":\"5c6d4100-08ce-488b-9583-e0b0c15d5be4\",\"type\":\"Line\"},{\"attributes\":{\"fill_color\":{\"value\":\"green\"},\"line_color\":{\"value\":\"green\"},\"top\":{\"field\":\"volume\"},\"width\":{\"value\":1945993846.1538465},\"x\":{\"field\":\"date\"}},\"id\":\"b8437f7b-8087-43a9-878c-f9132dbc2f37\",\"type\":\"VBar\"},{\"attributes\":{\"months\":[0,4,8]},\"id\":\"07e43761-4a37-4af5-a267-db3fd0052681\",\"type\":\"MonthsTicker\"},{\"attributes\":{},\"id\":\"8f288052-dedc-46a1-8ab3-084772a4f662\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"8260983d-3280-46e6-80d4-2031abc63faf\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1b33e5eb-22bb-4ab9-af96-a622dcc51bc2\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"8f288052-dedc-46a1-8ab3-084772a4f662\",\"type\":\"BasicTicker\"},\"y_range_name\":\"size\"},\"id\":\"407ed82e-58c5-4067-8263-acbd5ef2240e\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"75b23ae4-7018-4413-8987-42c6c4e49ea8\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"02cbb28e-47d9-46dd-b59a-18fcb10082c1\",\"type\":\"VBar\"},\"hover_glyph\":null,\"nonselection_glyph\":{\"id\":\"702b7cf7-3d74-4db6-8ff0-6d379994634a\",\"type\":\"VBar\"},\"selection_glyph\":null},\"id\":\"3ca6343c-6450-4dc9-b2b5-4126013b084c\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"line_color\":{\"value\":\"red\"},\"x\":{\"field\":\"date\"},\"y\":{\"field\":\"size\"}},\"id\":\"9f7b82d4-d747-4139-b570-825ae72e5335\",\"type\":\"Line\"},{\"attributes\":{\"data_source\":{\"id\":\"8a5ad4ef-2a14-4ef4-93cd-07d7965b56fc\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"9f7b82d4-d747-4139-b570-825ae72e5335\",\"type\":\"Line\"},\"hover_glyph\":null,\"nonselection_glyph\":{\"id\":\"5c6d4100-08ce-488b-9583-e0b0c15d5be4\",\"type\":\"Line\"},\"selection_glyph\":null,\"y_range_name\":\"size\"},\"id\":\"1d1b8a1a-eb02-458a-8729-efc94380a602\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"days\":[1,4,7,10,13,16,19,22,25,28]},\"id\":\"967efbdc-0488-444c-a64e-fa22201a6b93\",\"type\":\"DaysTicker\"},{\"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\":\"34820e0f-de6e-4776-96b6-44e63817056a\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"bounds\":\"auto\",\"callback\":null,\"end\":19565},\"id\":\"afe072da-9289-49e5-9210-6561f021d3e0\",\"type\":\"Range1d\"},{\"attributes\":{\"days\":[1,8,15,22]},\"id\":\"a27f1530-0899-451e-b5f2-51d92db92901\",\"type\":\"DaysTicker\"},{\"attributes\":{},\"id\":\"1b33e5eb-22bb-4ab9-af96-a622dcc51bc2\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"418dddcf-3b30-43be-8c03-c5daf88124bc\",\"type\":\"BasicTicker\"},{\"attributes\":{\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"58ffd6f3-5603-41f9-a541-79bdbafae613\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"6eacd83c-df56-4d10-b1e6-910dea846f90\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"b8437f7b-8087-43a9-878c-f9132dbc2f37\",\"type\":\"VBar\"},\"hover_glyph\":null,\"nonselection_glyph\":{\"id\":\"3a98df8e-7e51-4963-99c8-41fa1373a482\",\"type\":\"VBar\"},\"selection_glyph\":null},\"id\":\"419506ef-b027-4218-8320-58d4894c80e1\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"dimension\":1,\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"418dddcf-3b30-43be-8c03-c5daf88124bc\",\"type\":\"BasicTicker\"}},\"id\":\"54118f61-cd87-426a-93d2-63d7af5080e0\",\"type\":\"Grid\"},{\"attributes\":{\"bounds\":\"auto\",\"callback\":null},\"id\":\"a69ada92-9041-4825-a8b4-a0a44c200928\",\"type\":\"DataRange1d\"},{\"attributes\":{\"months\":[0,1,2,3,4,5,6,7,8,9,10,11]},\"id\":\"f67f8393-3736-467f-9d6a-4368bf458d7c\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"months\":[0,6]},\"id\":\"e6f9ec90-73e2-4608-b3b0-ee3a0afdcf25\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"volume\",\"date\"],\"data\":{\"date\":[1451606400000.0,1454284800000.0,1456790400000.0,1459468800000.0,1462060800000.0,1464739200000.0,1467331200000.0,1470009600000.0,1472688000000.0,1475280000000.0,1477958400000.0,1480550400000.0,1483228800000.0],\"volume\":[4401,4282,4186,3844,5241,4319,4473,4018,4069,4184,5761,4409,250]}},\"id\":\"75b23ae4-7018-4413-8987-42c6c4e49ea8\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"max_interval\":500.0,\"num_minor_ticks\":0},\"id\":\"9d0b166a-c883-4a06-9f17-8510ae6ea90c\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"658c072f-29eb-4c23-887c-6dfb9aa77cd6\",\"type\":\"DatetimeTicker\"}},\"id\":\"8b45a63c-dd42-4b43-8dd9-8c0d9faa23d6\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"volume\",\"date\"],\"data\":{\"date\":[1451606400000.0,1454284800000.0,1456790400000.0,1459468800000.0,1462060800000.0,1464739200000.0,1467331200000.0,1470009600000.0,1472688000000.0,1475280000000.0,1477958400000.0,1480550400000.0,1483228800000.0],\"volume\":[440.1,428.20000000000005,418.6,384.40000000000003,524.1,431.90000000000003,447.3,401.8,406.90000000000003,418.40000000000003,576.1,440.90000000000003,25.0]}},\"id\":\"6eacd83c-df56-4d10-b1e6-910dea846f90\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"6f846f5a-3bb0-4264-ac01-793dbff7402a\",\"type\":\"DatetimeTickFormatter\"},\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"658c072f-29eb-4c23-887c-6dfb9aa77cd6\",\"type\":\"DatetimeTicker\"}},\"id\":\"5051d3d4-cb47-4d12-ad5e-af1d579e834d\",\"type\":\"DatetimeAxis\"},{\"attributes\":{\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"9504cbcf-004a-4187-bcaf-eda5e75850fd\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"ce5ba02b-7d25-4296-8da1-d33d3bcc0c6f\",\"type\":\"ToolEvents\"},{\"attributes\":{\"bounds\":\"auto\",\"callback\":null,\"end\":5761},\"id\":\"11c87eb0-d97a-4628-89ff-66c4f37311ae\",\"type\":\"Range1d\"},{\"attributes\":{\"days\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]},\"id\":\"c60c4770-8791-448d-86ef-6e2b50f8e146\",\"type\":\"DaysTicker\"},{\"attributes\":{},\"id\":\"96741a80-b042-4e53-a8ab-7a0a4ef1e30d\",\"type\":\"YearsTicker\"},{\"attributes\":{\"base\":60,\"mantissas\":[1,2,5,10,15,20,30],\"max_interval\":1800000.0,\"min_interval\":1000.0,\"num_minor_ticks\":0},\"id\":\"8fe994fd-3a89-4fe4-a893-a32706aacfe6\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"date\",\"size\"],\"data\":{\"date\":[1451606400000.0,1454284800000.0,1456790400000.0,1459468800000.0,1462060800000.0,1464739200000.0,1467331200000.0,1470009600000.0,1472688000000.0,1475280000000.0,1477958400000.0,1480550400000.0,1483228800000.0],\"size\":[16573,13585,19565,14038,16160,14228,16782,18762,16537,15497,14253,14823,507]}},\"id\":\"8a5ad4ef-2a14-4ef4-93cd-07d7965b56fc\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"plot\":{\"id\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"8a72e1f4-6e8b-4db6-ae51-1fe070611b83\",\"type\":\"SaveTool\"},{\"attributes\":{\"plot\":null,\"text\":\"\"},\"id\":\"021cc22f-b301-4c10-9806-f6ea441bce51\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"6f846f5a-3bb0-4264-ac01-793dbff7402a\",\"type\":\"DatetimeTickFormatter\"}],\"root_ids\":[\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\"]},\"title\":\"Bokeh Application\",\"version\":\"0.12.4\"}};\n",
" var render_items = [{\"docid\":\"d2f5e816-9498-4acf-9e87-256e2a8fe471\",\"elementid\":\"e095a58d-479f-494f-a4ed-8c12d5d31f2b\",\"modelid\":\"8f8de0be-6eac-427e-9f4a-e20d21d93e83\",\"notebook_comms_target\":\"bbd2ee72-8aaf-4558-be28-e3765dc85abb\"}];\n",
" \n",
" Bokeh.embed.embed_items(docs_json, render_items);\n",
" };\n",
" if (document.readyState != \"loading\") fn();\n",
" else document.addEventListener(\"DOMContentLoaded\", fn);\n",
" })();\n",
" },\n",
" function(Bokeh) {\n",
" }\n",
" ];\n",
" \n",
" function run_inline_js() {\n",
" \n",
" if ((window.Bokeh !== undefined) || (force === true)) {\n",
" for (var i = 0; i < inline_js.length; i++) {\n",
" inline_js[i](window.Bokeh);\n",
" }if (force === true) {\n",
" display_loaded();\n",
" }} else if (Date.now() < window._bokeh_timeout) {\n",
" setTimeout(run_inline_js, 100);\n",
" } else if (!window._bokeh_failed_load) {\n",
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
" window._bokeh_failed_load = true;\n",
" } else if (force !== true) {\n",
" var cell = $(document.getElementById(\"e095a58d-479f-494f-a4ed-8c12d5d31f2b\")).parents('.cell').data().cell;\n",
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
" }\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));\n",
"</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def get_data(freq='MS'):\n",
" return pd.DataFrame(srs.groupby(pd.Grouper(freq=freq)).sum())\n",
"\n",
"def get_data2(freq='MS'):\n",
" return pd.DataFrame(srs2.groupby(pd.Grouper(freq=freq)).sum())\n",
"\n",
"source = ColumnDataSource(data=ColumnDataSource.from_df(get_data()))\n",
"source2 = ColumnDataSource(data=ColumnDataSource.from_df(get_data2()))\n",
"source_s = ColumnDataSource(data=ColumnDataSource.from_df(get_data() * .1))\n",
"\n",
"def get_width():\n",
" mindate = min(source.data['date'])\n",
" maxdate = max(source.data['date'])\n",
" return 0.8 * (maxdate-mindate).total_seconds() * 1000 / len(source.data['date'])\n",
"\n",
"def get_width_s():\n",
" mindate = min(source_s.data['date'])\n",
" maxdate = max(source_s.data['date'])\n",
" return 0.8 * (maxdate-mindate).total_seconds() * 1000 / len(source_s.data['date'])\n",
"\n",
"f = figure(plot_width=550, plot_height=400, x_axis_type=\"datetime\", y_range=Range1d(0, max(source.data['volume']), bounds='auto'))\n",
"f.x_range.bounds='auto'\n",
"\n",
"f.extra_y_ranges = {\n",
" \"size\": Range1d(bounds='auto', start=0, end=max(source2.data['size'])),\n",
"}\n",
"\n",
"f.add_layout(LinearAxis(y_range_name='size'), 'right')\n",
"\n",
"r = f.vbar(source=source, top='volume', x='date', width=get_width())\n",
"r2 = f.vbar(source=source_s, top='volume', x='date', width=get_width(), color='green')\n",
"\n",
"f.line(source=source2, x='date', y='size', color='red', y_range_name='size')\n",
"f.tools[2].dimensions = 'width'\n",
"\n",
"handle = show(f, notebook_handle=True)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2017-01-27T21:46:59.693339",
"start_time": "2017-01-27T21:46:59.595852"
},
"collapsed": false,
"extensions": {
"jupyter_dashboards": {
"version": 1,
"views": {
"grid_default": {
"col": 0,
"height": 2,
"hidden": false,
"row": 0,
"width": 12
},
"report_default": {
"hidden": false
}
}
}
}
},
"outputs": [],
"source": [
"def update_data(freq={'Quarter': 'QS', 'Month': 'MS', 'Week': 'W'}):\n",
" source.data = ColumnDataSource.from_df(get_data(freq))\n",
" source2.data = ColumnDataSource.from_df(get_data2(freq))\n",
" source_s.data = ColumnDataSource.from_df(get_data(freq) * .1)\n",
"\n",
" r.glyph.width = get_width()\n",
" r2.glyph.width = get_width_s()\n",
"\n",
" f.y_range.end = max(source.data['volume'])\n",
" f.extra_y_ranges['size'].end = max(source2.data['size'])\n",
"\n",
" push_notebook(handle=handle)\n",
" \n",
"i = interact(update_data)"
]
}
],
"metadata": {
"extensions": {
"jupyter_dashboards": {
"activeView": "grid_default",
"version": 1,
"views": {
"grid_default": {
"cellMargin": 10,
"defaultCellHeight": 20,
"layoutStrategy": "packed",
"maxColumns": 12,
"name": "grid",
"type": "grid"
},
"report_default": {
"name": "report",
"type": "report"
}
}
}
},
"hide_input": false,
"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.5"
},
"widgets": {
"state": {
"8cbfc0a2982f4ddda457c5c18ebc6c5d": {
"views": [
{
"cell_index": 3
}
]
}
},
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment