{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", " \n", "

Bokeh Tutorial

\n", "
\n", "\n", "

05. Presentation and Layout

" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " Loading BokehJS ...\n", "
" ] }, "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 != null && id in Bokeh.index) {\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 id = msg.content.text.trim();\n", " if (id in Bokeh.index) {\n", " Bokeh.index[id].model.document.clear();\n", " delete Bokeh.index[id];\n", " }\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[toinsert.length - 1].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[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n", " toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\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[toinsert.length - 1]);\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", " \"
\\n\"+\n", " \"

\\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", " \"

\\n\"+\n", " \"\\n\"+\n", " \"\\n\"+\n", " \"from bokeh.resources import INLINE\\n\"+\n", " \"output_notebook(resources=INLINE)\\n\"+\n", " \"\\n\"+\n", " \"
\"}};\n", "\n", " function display_loaded() {\n", " var el = document.getElementById(\"1001\");\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) {\n", " if (callback != null)\n", " callback();\n", " });\n", " } finally {\n", " delete root._bokeh_onload_callbacks\n", " }\n", " console.debug(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(css_urls, js_urls, callback) {\n", " if (css_urls == null) css_urls = [];\n", " if (js_urls == null) js_urls = [];\n", "\n", " root._bokeh_onload_callbacks.push(callback);\n", " if (root._bokeh_is_loading > 0) {\n", " console.debug(\"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.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " root._bokeh_is_loading = css_urls.length + js_urls.length;\n", "\n", " function on_load() {\n", " root._bokeh_is_loading--;\n", " if (root._bokeh_is_loading === 0) {\n", " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", " run_callbacks()\n", " }\n", " }\n", "\n", " function on_error() {\n", " console.error(\"failed to load \" + url);\n", " }\n", "\n", " for (var i = 0; i < css_urls.length; i++) {\n", " var url = css_urls[i];\n", " const element = document.createElement(\"link\");\n", " element.onload = on_load;\n", " element.onerror = on_error;\n", " element.rel = \"stylesheet\";\n", " element.type = \"text/css\";\n", " element.href = url;\n", " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", " document.body.appendChild(element);\n", " }\n", "\n", " const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.0.1.min.js\": \"JpP8FXbgAZLkfur7LiK3j9AGBhHNIvF742meBJrjO2ShJDhCG2I1uVvW+0DUtrmc\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.1.min.js\": \"xZlADit0Q04ISQEdKg2k3L4W9AwQBAuDs9nJL9fM/WwzL1tEU9VPNezOFX0nLEAz\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.0.1.min.js\": \"4BuPRZkdMKSnj3zoxiNrQ86XgNw0rYmBOxe7nshquXwwcauupgBF2DHLVG1WuZlV\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.0.1.min.js\": \"Dv1SQ87hmDqK6S5OhBf0bCuwAEvL5QYL0PuR/F1SPVhCS/r/abjkbpKDYL2zeM19\"};\n", "\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var element = document.createElement('script');\n", " element.onload = on_load;\n", " element.onerror = on_error;\n", " element.async = false;\n", " element.src = url;\n", " if (url in hashes) {\n", " element.crossOrigin = \"anonymous\";\n", " element.integrity = \"sha384-\" + hashes[url];\n", " }\n", " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.head.appendChild(element);\n", " }\n", " };var element = document.getElementById(\"1001\");\n", " if (element == null) {\n", " console.error(\"Bokeh: ERROR: autoload.js configured with elementid '1001' but no matching script tag was found. \")\n", " return false;\n", " }\n", "\n", " function inject_raw_css(css) {\n", " const element = document.createElement(\"style\");\n", " element.appendChild(document.createTextNode(css));\n", " document.body.appendChild(element);\n", " }\n", "\n", " \n", " var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.0.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.0.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.0.1.min.js\"];\n", " var css_urls = [];\n", " \n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " function(Bokeh) {\n", " \n", " \n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " \n", " if (root.Bokeh !== undefined || force === true) {\n", " \n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i].call(root, root.Bokeh);\n", " }\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(\"1001\")).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.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(css_urls, js_urls, function() {\n", " console.debug(\"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 \"
\\n\"+\n \"

\\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 \"

\\n\"+\n \"\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"
\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"1001\");\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) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"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.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error() {\n console.error(\"failed to load \" + url);\n }\n\n for (var i = 0; i < css_urls.length; i++) {\n var url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.0.1.min.js\": \"JpP8FXbgAZLkfur7LiK3j9AGBhHNIvF742meBJrjO2ShJDhCG2I1uVvW+0DUtrmc\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.1.min.js\": \"xZlADit0Q04ISQEdKg2k3L4W9AwQBAuDs9nJL9fM/WwzL1tEU9VPNezOFX0nLEAz\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.0.1.min.js\": \"4BuPRZkdMKSnj3zoxiNrQ86XgNw0rYmBOxe7nshquXwwcauupgBF2DHLVG1WuZlV\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.0.1.min.js\": \"Dv1SQ87hmDqK6S5OhBf0bCuwAEvL5QYL0PuR/F1SPVhCS/r/abjkbpKDYL2zeM19\"};\n\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n if (url in hashes) {\n element.crossOrigin = \"anonymous\";\n element.integrity = \"sha384-\" + hashes[url];\n }\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };var element = document.getElementById(\"1001\");\n if (element == null) {\n console.error(\"Bokeh: ERROR: autoload.js configured with elementid '1001' but no matching script tag was found. \")\n return false;\n }\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n \n var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.0.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.0.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.0.1.min.js\"];\n var css_urls = [];\n \n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n function(Bokeh) {\n \n \n }\n ];\n\n function run_inline_js() {\n \n if (root.Bokeh !== undefined || force === true) {\n \n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\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(\"1001\")).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.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from bokeh.io import output_notebook, show\n", "from bokeh.plotting import figure\n", "\n", "output_notebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the previous chapters we started to learn how to create single plots using differnet kinds of data. But we often want to plot more than one thing. Bokeh plots can be individually embedded in HTML documents, but it's often easier to\n", "combine multiple plots in one of Bokeh's built-in layouts. We will learn how to do that in this chapter\n", "\n", "The cell below defines a few data variables we will use in examples." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "x = list(range(11))\n", "y0, y1, y2 = x, [10-i for i in x], [abs(i-5) for i in x]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Rows and Columns\n", "The `bokeh.layouts` modules provides the ``row`` and ``column`` functions to arrange plot objects in vertical or horizontal layouts. Below is an example of three plots arranged in a row." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "(function(root) {\n", " function embed_document(root) {\n", " \n", " var docs_json = {\"93fd67c1-e934-4920-b75e-ec6290893a00\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"1002\"},{\"id\":\"1038\"},{\"id\":\"1074\"}]},\"id\":\"1110\",\"type\":\"Row\"},{\"attributes\":{\"formatter\":{\"id\":\"1117\"},\"ticker\":{\"id\":\"1012\"}},\"id\":\"1011\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1136\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1137\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1011\"},\"ticker\":null},\"id\":\"1014\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1119\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"dimension\":1,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"1025\"}},\"id\":\"1021\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"ResetTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1025\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"formatter\":{\"id\":\"1123\"},\"ticker\":{\"id\":\"1052\"}},\"id\":\"1051\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1125\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1127\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1033\"}},\"id\":\"1037\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1052\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1039\",\"type\":\"DataRange1d\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1019\"},{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"}]},\"id\":\"1026\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1130\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data_source\":{\"id\":\"1105\"},\"glyph\":{\"id\":\"1106\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1107\"},\"selection_glyph\":null,\"view\":{\"id\":\"1109\"}},\"id\":\"1108\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1131\",\"type\":\"Selection\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"navy\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"navy\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1035\",\"type\":\"Circle\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10],\"y\":[10,9,8,7,6,5,4,3,2,1,0]},\"selected\":{\"id\":\"1134\"},\"selection_policy\":{\"id\":\"1133\"}},\"id\":\"1069\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"firebrick\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"firebrick\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1070\",\"type\":\"Triangle\"},{\"attributes\":{\"data_source\":{\"id\":\"1033\"},\"glyph\":{\"id\":\"1034\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1035\"},\"selection_glyph\":null,\"view\":{\"id\":\"1037\"}},\"id\":\"1036\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"1121\"},\"ticker\":{\"id\":\"1048\"}},\"id\":\"1047\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"olive\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"olive\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1107\",\"type\":\"Square\"},{\"attributes\":{},\"id\":\"1043\",\"type\":\"LinearScale\"},{\"attributes\":{\"below\":[{\"id\":\"1011\"}],\"center\":[{\"id\":\"1014\"},{\"id\":\"1018\"}],\"left\":[{\"id\":\"1015\"}],\"plot_height\":250,\"plot_width\":250,\"renderers\":[{\"id\":\"1036\"}],\"title\":{\"id\":\"1112\"},\"toolbar\":{\"id\":\"1026\"},\"x_range\":{\"id\":\"1003\"},\"x_scale\":{\"id\":\"1007\"},\"y_range\":{\"id\":\"1005\"},\"y_scale\":{\"id\":\"1009\"}},\"id\":\"1002\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"below\":[{\"id\":\"1047\"}],\"center\":[{\"id\":\"1050\"},{\"id\":\"1054\"}],\"left\":[{\"id\":\"1051\"}],\"plot_height\":250,\"plot_width\":250,\"renderers\":[{\"id\":\"1072\"}],\"title\":{\"id\":\"1114\"},\"toolbar\":{\"id\":\"1062\"},\"x_range\":{\"id\":\"1039\"},\"x_scale\":{\"id\":\"1043\"},\"y_range\":{\"id\":\"1041\"},\"y_scale\":{\"id\":\"1045\"}},\"id\":\"1038\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1041\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"navy\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"navy\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1034\",\"type\":\"Circle\"},{\"attributes\":{\"axis\":{\"id\":\"1051\"},\"dimension\":1,\"ticker\":null},\"id\":\"1054\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10],\"y\":[0,1,2,3,4,5,6,7,8,9,10]},\"selected\":{\"id\":\"1131\"},\"selection_policy\":{\"id\":\"1130\"}},\"id\":\"1033\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1048\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1003\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1047\"},\"ticker\":null},\"id\":\"1050\",\"type\":\"Grid\"},{\"attributes\":{\"below\":[{\"id\":\"1083\"}],\"center\":[{\"id\":\"1086\"},{\"id\":\"1090\"}],\"left\":[{\"id\":\"1087\"}],\"plot_height\":250,\"plot_width\":250,\"renderers\":[{\"id\":\"1108\"}],\"title\":{\"id\":\"1116\"},\"toolbar\":{\"id\":\"1098\"},\"x_range\":{\"id\":\"1075\"},\"x_scale\":{\"id\":\"1079\"},\"y_range\":{\"id\":\"1077\"},\"y_scale\":{\"id\":\"1081\"}},\"id\":\"1074\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1055\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1056\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1060\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1061\"}},\"id\":\"1057\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1058\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1059\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1134\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1133\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"overlay\":{\"id\":\"1097\"}},\"id\":\"1093\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1094\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1095\",\"type\":\"ResetTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1061\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"1105\"}},\"id\":\"1109\",\"type\":\"CDSView\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1112\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1075\",\"type\":\"DataRange1d\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1114\",\"type\":\"Title\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1055\"},{\"id\":\"1056\"},{\"id\":\"1057\"},{\"id\":\"1058\"},{\"id\":\"1059\"},{\"id\":\"1060\"}]},\"id\":\"1062\",\"type\":\"Toolbar\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1116\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"1069\"}},\"id\":\"1073\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"1069\"},\"glyph\":{\"id\":\"1070\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1071\"},\"selection_glyph\":null,\"view\":{\"id\":\"1073\"}},\"id\":\"1072\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"firebrick\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"firebrick\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1071\",\"type\":\"Triangle\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"olive\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"olive\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1106\",\"type\":\"Square\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10],\"y\":[5,4,3,2,1,0,1,2,3,4,5]},\"selected\":{\"id\":\"1137\"},\"selection_policy\":{\"id\":\"1136\"}},\"id\":\"1105\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"1125\"},\"ticker\":{\"id\":\"1084\"}},\"id\":\"1083\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1079\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1077\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1117\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1081\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1091\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1084\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1083\"},\"ticker\":null},\"id\":\"1086\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1119\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1127\"},\"ticker\":{\"id\":\"1088\"}},\"id\":\"1087\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1088\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1087\"},\"dimension\":1,\"ticker\":null},\"id\":\"1090\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1091\"},{\"id\":\"1092\"},{\"id\":\"1093\"},{\"id\":\"1094\"},{\"id\":\"1095\"},{\"id\":\"1096\"}]},\"id\":\"1098\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1092\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1096\",\"type\":\"HelpTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1097\",\"type\":\"BoxAnnotation\"}],\"root_ids\":[\"1110\"]},\"title\":\"Bokeh Application\",\"version\":\"2.0.1\"}};\n", " var render_items = [{\"docid\":\"93fd67c1-e934-4920-b75e-ec6290893a00\",\"root_ids\":[\"1110\"],\"roots\":{\"1110\":\"eeaed001-55c8-44ba-bd5e-4887c7578d24\"}}];\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", " clearInterval(timer);\n", " embed_document(root);\n", " } else {\n", " attempts++;\n", " if (attempts > 100) {\n", " clearInterval(timer);\n", " console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n", " }\n", " }\n", " }, 10, root)\n", " }\n", "})(window);" ], "application/vnd.bokehjs_exec.v0+json": "" }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "id": "1110" } }, "output_type": "display_data" } ], "source": [ "from bokeh.layouts import row\n", "\n", "# create a new plot\n", "s1 = figure(width=250, plot_height=250)\n", "s1.circle(x, y0, size=10, color=\"navy\", alpha=0.5)\n", "\n", "# create another one\n", "s2 = figure(width=250, height=250)\n", "s2.triangle(x, y1, size=10, color=\"firebrick\", alpha=0.5)\n", "\n", "# create and another\n", "s3 = figure(width=250, height=250)\n", "s3.square(x, y2, size=10, color=\"olive\", alpha=0.5)\n", "\n", "# show the results in a row\n", "show(row(s1, s2, s3))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# EXERCISE: use column to arrange a few plots vertically (don't forget to import column)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Grid plots\n", "\n", "Bokeh also provides a `gridplot` layout in `bokeh.layouts` for arranging plots in a grid, as show in the example below." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "(function(root) {\n", " function embed_document(root) {\n", " \n", " var docs_json = {\"2107de56-148c-497e-909d-34f46d8ba2a4\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[[{\"id\":\"1300\"},0,0],[{\"id\":\"1336\"},0,1],[{\"id\":\"1372\"},1,0]]},\"id\":\"1438\",\"type\":\"GridBox\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1317\"},{\"id\":\"1318\"},{\"id\":\"1319\"},{\"id\":\"1320\"},{\"id\":\"1321\"},{\"id\":\"1322\"}]},\"id\":\"1324\",\"type\":\"Toolbar\"},{\"attributes\":{\"below\":[{\"id\":\"1345\"}],\"center\":[{\"id\":\"1348\"},{\"id\":\"1352\"}],\"left\":[{\"id\":\"1349\"}],\"plot_height\":250,\"plot_width\":250,\"renderers\":[{\"id\":\"1370\"}],\"title\":{\"id\":\"1419\"},\"toolbar\":{\"id\":\"1360\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1337\"},\"x_scale\":{\"id\":\"1341\"},\"y_range\":{\"id\":\"1339\"},\"y_scale\":{\"id\":\"1343\"}},\"id\":\"1336\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1320\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1317\",\"type\":\"PanTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"navy\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"navy\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1332\",\"type\":\"Circle\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10],\"y\":[0,1,2,3,4,5,6,7,8,9,10]},\"selected\":{\"id\":\"1416\"},\"selection_policy\":{\"id\":\"1415\"}},\"id\":\"1331\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1301\",\"type\":\"DataRange1d\"},{\"attributes\":{\"below\":[{\"id\":\"1309\"}],\"center\":[{\"id\":\"1312\"},{\"id\":\"1316\"}],\"left\":[{\"id\":\"1313\"}],\"plot_height\":250,\"plot_width\":250,\"renderers\":[{\"id\":\"1334\"}],\"title\":{\"id\":\"1409\"},\"toolbar\":{\"id\":\"1324\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1301\"},\"x_scale\":{\"id\":\"1305\"},\"y_range\":{\"id\":\"1303\"},\"y_scale\":{\"id\":\"1307\"}},\"id\":\"1300\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"below\":[{\"id\":\"1381\"}],\"center\":[{\"id\":\"1384\"},{\"id\":\"1388\"}],\"left\":[{\"id\":\"1385\"}],\"plot_height\":250,\"plot_width\":250,\"renderers\":[{\"id\":\"1406\"}],\"title\":{\"id\":\"1429\"},\"toolbar\":{\"id\":\"1396\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1373\"},\"x_scale\":{\"id\":\"1377\"},\"y_range\":{\"id\":\"1375\"},\"y_scale\":{\"id\":\"1379\"}},\"id\":\"1372\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"1410\"},\"ticker\":{\"id\":\"1310\"}},\"id\":\"1309\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1318\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1305\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1303\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1307\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1323\"}},\"id\":\"1319\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1310\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1309\"},\"ticker\":null},\"id\":\"1312\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1412\"},\"ticker\":{\"id\":\"1314\"}},\"id\":\"1313\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1314\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1313\"},\"dimension\":1,\"ticker\":null},\"id\":\"1316\",\"type\":\"Grid\"},{\"attributes\":{\"data_source\":{\"id\":\"1403\"},\"glyph\":{\"id\":\"1404\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1405\"},\"selection_glyph\":null,\"view\":{\"id\":\"1407\"}},\"id\":\"1406\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1409\",\"type\":\"Title\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"olive\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"olive\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1405\",\"type\":\"Square\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1359\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"1403\"}},\"id\":\"1407\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1323\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1322\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1321\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1426\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1425\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1410\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1412\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1367\"}},\"id\":\"1371\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"1367\"},\"glyph\":{\"id\":\"1368\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1369\"},\"selection_glyph\":null,\"view\":{\"id\":\"1371\"}},\"id\":\"1370\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1339\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"firebrick\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"firebrick\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1369\",\"type\":\"Triangle\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"olive\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"olive\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1404\",\"type\":\"Square\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10],\"y\":[5,4,3,2,1,0,1,2,3,4,5]},\"selected\":{\"id\":\"1436\"},\"selection_policy\":{\"id\":\"1435\"}},\"id\":\"1403\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1373\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1379\",\"type\":\"LinearScale\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1429\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1377\",\"type\":\"LinearScale\"},{\"attributes\":{\"source\":{\"id\":\"1331\"}},\"id\":\"1335\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1381\"},\"ticker\":null},\"id\":\"1384\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1415\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1375\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data_source\":{\"id\":\"1331\"},\"glyph\":{\"id\":\"1332\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1333\"},\"selection_glyph\":null,\"view\":{\"id\":\"1335\"}},\"id\":\"1334\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"navy\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"navy\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1333\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1416\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"1430\"},\"ticker\":{\"id\":\"1382\"}},\"id\":\"1381\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"firebrick\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"firebrick\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1368\",\"type\":\"Triangle\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10],\"y\":[10,9,8,7,6,5,4,3,2,1,0]},\"selected\":{\"id\":\"1426\"},\"selection_policy\":{\"id\":\"1425\"}},\"id\":\"1367\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1389\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1337\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1382\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1432\"},\"ticker\":{\"id\":\"1386\"}},\"id\":\"1385\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1341\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1386\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1420\"},\"ticker\":{\"id\":\"1346\"}},\"id\":\"1345\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1385\"},\"dimension\":1,\"ticker\":null},\"id\":\"1388\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1343\",\"type\":\"LinearScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1389\"},{\"id\":\"1390\"},{\"id\":\"1391\"},{\"id\":\"1392\"},{\"id\":\"1393\"},{\"id\":\"1394\"}]},\"id\":\"1396\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1390\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1430\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1394\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1346\",\"type\":\"BasicTicker\"},{\"attributes\":{\"overlay\":{\"id\":\"1395\"}},\"id\":\"1391\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1392\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1353\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1393\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"1345\"},\"ticker\":null},\"id\":\"1348\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1432\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1422\"},\"ticker\":{\"id\":\"1350\"}},\"id\":\"1349\",\"type\":\"LinearAxis\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1419\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1350\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1349\"},\"dimension\":1,\"ticker\":null},\"id\":\"1352\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1353\"},{\"id\":\"1354\"},{\"id\":\"1355\"},{\"id\":\"1356\"},{\"id\":\"1357\"},{\"id\":\"1358\"}]},\"id\":\"1360\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1354\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1358\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1359\"}},\"id\":\"1355\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1356\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1357\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1420\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1435\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1395\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1436\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1422\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"1438\"]},\"title\":\"Bokeh Application\",\"version\":\"2.0.1\"}};\n", " var render_items = [{\"docid\":\"2107de56-148c-497e-909d-34f46d8ba2a4\",\"root_ids\":[\"1438\"],\"roots\":{\"1438\":\"641491c6-6ab8-4a61-ad77-c6bedea5731d\"}}];\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", " clearInterval(timer);\n", " embed_document(root);\n", " } else {\n", " attempts++;\n", " if (attempts > 100) {\n", " clearInterval(timer);\n", " console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n", " }\n", " }\n", " }, 10, root)\n", " }\n", "})(window);" ], "application/vnd.bokehjs_exec.v0+json": "" }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "id": "1438" } }, "output_type": "display_data" } ], "source": [ "from bokeh.layouts import gridplot\n", "\n", "# create a new plot\n", "s1 = figure(width=250, plot_height=250)\n", "s1.circle(x, y0, size=10, color=\"navy\", alpha=0.5)\n", "\n", "# create another one\n", "s2 = figure(width=250, height=250)\n", "s2.triangle(x, y1, size=10, color=\"firebrick\", alpha=0.5)\n", "\n", "# create and another\n", "s3 = figure(width=250, height=250)\n", "s3.square(x, y2, size=10, color=\"olive\", alpha=0.5)\n", "\n", "# put all the plots in a gridplot\n", "p = gridplot([[s1, s2], [s3, None]], toolbar_location=None)\n", "\n", "# show the results\n", "show(p)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# EXERCISE: create a gridplot of your own\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Next Section" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Click on this link to go to the next notebook: [06 - Linking and Interactions](06%20-%20Linking%20and%20Interactions.ipynb).\n", "\n", "To go back to the overview, click [here](00%20-%20Introduction%20and%20Setup.ipynb)." ] }, { "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.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }