{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercise 6.2: Axes with logarithmic scale and error bars\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sometimes you need to plot your data with a logarithmic scale. As an example, let's consider the classic genetic switch engineered by Jim Collins and coworkers ([Gardner, et al., *Nature*, **403**, 339, 2000](https://doi.org/10.1038/35002131)). This genetic switch was incorporated into *E. coli* and is inducible by adjusting the concentration of the lactose analog IPTG. The readout is the fluorescence intensity of GFP.\n", "\n", "The data set has the IPTG concentrations and GFP fluorescence intensity. The data are in the file `~/git/data/collins_switch.csv`. Let's look at it." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# Data digitized from Fig. 5a of Gardner, et al., *Nature*, **403**, 339, 2000. The last column gives the standard error of the mean normalized GFP intensity.\n", "[IPTG] (mM),normalized GFP expression (a.u.),sem\n", "0.001000,0.004090,0.003475\n", "0.010000,0.010225,0.002268\n", "0.020000,0.022495,0.004781\n", "0.030000,0.034765,0.003000\n", "0.040000,0.067485,0.006604\n", "0.040000,0.668712,0.087862\n", "0.060000,0.740286,0.045853\n", "0.100000,0.840491,0.058986\n", "0.300000,0.936605,0.026931\n", "0.600000,0.961145,0.093553\n", "1.000000,0.940695,0.037624\n", "3.000000,0.852761,0.059035\n", "6.000000,0.910020,0.051052\n", "10.000000,0.893661,0.042773\n" ] } ], "source": [ "!cat data/collins_switch.csv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It has two rows of non-data. Then, Column 1 is the IPTG concentration, column 2 is the normalized GFP expression level, and the last column is the standard error of the mean normalized GFP intensity. This gives the error bars, which we will plot momentarily. For now, we will just plot IPTG versus normalized GFP intensity.\n", "\n", "In looking at the data set, note that there are two entries for [IPTG] = 0.04 mM. At this concentration, the switch happens, and there are two populations of cells, one with high expression of GFP and one with low. The two data points represent these two populations of cells.\n", "\n", "**a)** Now, let's make a plot of IPTG versus GFP.\n", "\n", "1. Load in the data set using Pandas. Make sure you use the `comment` kwarg of pd.read_csv() properly.\n", "2. Make a plot of normalized GFP intensity (y-axis) versus IPTG concentration (x-axis).\n", "\n", "**b)** Now that you have done that, there are some problems with the plot. It is really hard to see the data points with low concentrations of IPTG. In fact, looking at the data set, the concentration of IPTG varies over four orders of magnitude. When you have data like this, it is wise to plot them on a logarithmic scale. You can specify the x-axis as logarithmic when you instantiate a figure with `bokeh.plotting.figure()` by using the `x_axis_type='log'` kwarg. (The obvious analogous kwarg applied for the y-axis.) For this data set, it is definitely best to have the x-axis on a logarithmic scale. Remake the plot you just did with the x-axis logarithmically scaled.\n", "\n", "When you make the x-axis logarithmically scaled, you will notice the Bokeh's formatting for the tick labels is pretty awful. Fixing this is a surprisingly difficult problem, and many plotting packages do not make pretty superscripts.\n", "\n", "**c)** The data set also contains the standard error of the mean, or SEM. The SEM is often displayed on plots as error bars. Now construct the plot with error bars.\n", "\n", "1. Add columns `error_low` and `error_high` to the data frame containing the Collins data. These will set the bottoms and tops of the error bars. You should base the values in these columns on the standard error of the mean (`sem`). Assuming a Gaussian model, the 95% confidence interval is ±1.96 times the s.e.m.\n", "2. Make a plot with the measured expression levels and the error bars. *Hint*: Check out the [Bokeh docs](https://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html) and think about what kind of glyph works best for error bars." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": 2, "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.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\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", " };\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.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.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.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\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 };\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.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.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": [ "import pandas as pd\n", "\n", "import bokeh.io\n", "import bokeh.plotting\n", "\n", "bokeh.io.output_notebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**a)** The initial plot is straightforward. We load in the data and directly make the plot." ] }, { "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 = {\"a8ad402d-3028-476e-8893-08ba97897d34\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1011\"}],\"center\":[{\"id\":\"1014\"},{\"id\":\"1018\"}],\"frame_height\":300,\"frame_width\":450,\"left\":[{\"id\":\"1015\"}],\"renderers\":[{\"id\":\"1037\"}],\"title\":{\"id\":\"1039\"},\"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\":{},\"id\":\"1024\",\"type\":\"HelpTool\"},{\"attributes\":{\"axis_label\":\"[IPTG] (mM)\",\"formatter\":{\"id\":\"1042\"},\"ticker\":{\"id\":\"1012\"}},\"id\":\"1011\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1003\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"dimension\":1,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1046\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"1011\"},\"ticker\":null},\"id\":\"1014\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis_label\":\"normalized GFP expression (a.u.)\",\"formatter\":{\"id\":\"1044\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"Selection\"},{\"attributes\":{\"data_source\":{\"id\":\"1033\"},\"glyph\":{\"id\":\"1035\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1036\"},\"selection_glyph\":null,\"view\":{\"id\":\"1038\"}},\"id\":\"1037\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"LinearScale\"},{\"attributes\":{\"source\":{\"id\":\"1033\"}},\"id\":\"1038\",\"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,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1025\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data\":{\"[IPTG] (mM)\":{\"__ndarray__\":\"/Knx0k1iUD97FK5H4XqEP3sUrkfhepQ/uB6F61G4nj97FK5H4XqkP3sUrkfheqQ/uB6F61G4rj+amZmZmZm5PzMzMzMzM9M/MzMzMzMz4z8AAAAAAADwPwAAAAAAAAhAAAAAAAAAGEAAAAAAAAAkQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],\"normalized GFP expression (a.u.)\":{\"__ndarray__\":\"VKnZA63AcD+pE9BE2PCEP9NIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP36kiAyr+O0/b9i2KLPB7j/SV5BmLBruP3i8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1haRuo9lXM/+n5qvHSTaD/CUl3Aywx7P6inj8AffrY/a9PYXgt6pz+D/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyiDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1045\"},\"selection_policy\":{\"id\":\"1046\"}},\"id\":\"1033\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1035\",\"type\":\"Circle\"},{\"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\":\"1019\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1025\"}},\"id\":\"1021\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1039\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"SaveTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1036\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1042\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"1002\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n", " var render_items = [{\"docid\":\"a8ad402d-3028-476e-8893-08ba97897d34\",\"root_ids\":[\"1002\"],\"roots\":{\"1002\":\"ef5ec20f-2506-455d-a963-ea063bfef647\"}}];\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": "1002" } }, "output_type": "display_data" } ], "source": [ "# Load in the data\n", "df = pd.read_csv('data/collins_switch.csv', comment='#')\n", "\n", "# For convenience\n", "x = '[IPTG] (mM)'\n", "y = 'normalized GFP expression (a.u.)'\n", "\n", "# Make the plot\n", "p = bokeh.plotting.figure(\n", " frame_height=300,\n", " frame_width=450,\n", " x_axis_label=x,\n", " y_axis_label=y,\n", ")\n", "\n", "p.circle(\n", " source=df,\n", " x=x,\n", " y=y,\n", ")\n", "\n", "bokeh.io.show(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**b)** We clearly need the $x$-axis to be on a log scale, so let's remake the plot." ] }, { "cell_type": "code", "execution_count": 4, "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 = {\"8a9899de-b6e7-4f96-ac4d-532faaff5317\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1111\"}],\"center\":[{\"id\":\"1114\"},{\"id\":\"1118\"}],\"left\":[{\"id\":\"1115\"}],\"plot_height\":300,\"plot_width\":450,\"renderers\":[{\"id\":\"1137\"}],\"title\":{\"id\":\"1148\"},\"toolbar\":{\"id\":\"1126\"},\"x_range\":{\"id\":\"1103\"},\"x_scale\":{\"id\":\"1107\"},\"y_range\":{\"id\":\"1105\"},\"y_scale\":{\"id\":\"1109\"}},\"id\":\"1102\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"num_minor_ticks\":10},\"id\":\"1112\",\"type\":\"LogTicker\"},{\"attributes\":{},\"id\":\"1122\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis_label\":\"normalized GFP expression (a.u.)\",\"formatter\":{\"id\":\"1153\"},\"ticker\":{\"id\":\"1116\"}},\"id\":\"1115\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1115\"},\"dimension\":1,\"ticker\":null},\"id\":\"1118\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1107\",\"type\":\"LogScale\"},{\"attributes\":{\"axis\":{\"id\":\"1111\"},\"ticker\":null},\"id\":\"1114\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1119\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1133\"},\"glyph\":{\"id\":\"1135\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1136\"},\"selection_glyph\":null,\"view\":{\"id\":\"1138\"}},\"id\":\"1137\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1135\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1105\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1136\",\"type\":\"Circle\"},{\"attributes\":{\"data\":{\"[IPTG] (mM)\":{\"__ndarray__\":\"/Knx0k1iUD97FK5H4XqEP3sUrkfhepQ/uB6F61G4nj97FK5H4XqkP3sUrkfheqQ/uB6F61G4rj+amZmZmZm5PzMzMzMzM9M/MzMzMzMz4z8AAAAAAADwPwAAAAAAAAhAAAAAAAAAGEAAAAAAAAAkQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],\"normalized GFP expression (a.u.)\":{\"__ndarray__\":\"VKnZA63AcD+pE9BE2PCEP9NIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP36kiAyr+O0/b9i2KLPB7j/SV5BmLBruP3i8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1haRuo9lXM/+n5qvHSTaD/CUl3Aywx7P6inj8AffrY/a9PYXgt6pz+D/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyiDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1154\"},\"selection_policy\":{\"id\":\"1155\"}},\"id\":\"1133\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"1133\"}},\"id\":\"1138\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1116\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis_label\":\"[IPTG] (mM)\",\"formatter\":{\"id\":\"1151\"},\"ticker\":{\"id\":\"1112\"}},\"id\":\"1111\",\"type\":\"LogAxis\"},{\"attributes\":{\"overlay\":{\"id\":\"1125\"}},\"id\":\"1121\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1148\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1103\",\"type\":\"DataRange1d\"},{\"attributes\":{\"ticker\":null},\"id\":\"1151\",\"type\":\"LogTickFormatter\"},{\"attributes\":{},\"id\":\"1155\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1154\",\"type\":\"Selection\"},{\"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,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1125\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1119\"},{\"id\":\"1120\"},{\"id\":\"1121\"},{\"id\":\"1122\"},{\"id\":\"1123\"},{\"id\":\"1124\"}]},\"id\":\"1126\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1109\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1120\",\"type\":\"WheelZoomTool\"}],\"root_ids\":[\"1102\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n", " var render_items = [{\"docid\":\"8a9899de-b6e7-4f96-ac4d-532faaff5317\",\"root_ids\":[\"1102\"],\"roots\":{\"1102\":\"d96f7e51-ce8f-4322-9782-dcc9b6e99764\"}}];\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": "1102" } }, "output_type": "display_data" } ], "source": [ "# Make the plot\n", "p = bokeh.plotting.figure(\n", " height=300,\n", " width=450,\n", " x_axis_label=x,\n", " y_axis_label=y,\n", " x_axis_type='log',\n", ")\n", "\n", "p.circle(\n", " source=df,\n", " x=x,\n", " y=y,\n", ")\n", "\n", "bokeh.io.show(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**c)** We start be adding the tops and bottoms of the error bars." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Add error bars to the DataFrame\n", "df['error_low'] = df['normalized GFP expression (a.u.)'] - 1.96*df['sem']\n", "df['error_high'] = df['normalized GFP expression (a.u.)'] + 1.96*df['sem']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we add them to the plot using the `segment()` method." ] }, { "cell_type": "code", "execution_count": 6, "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 = {\"266febba-0f33-4ab0-9660-e4ea5678ee70\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1111\"}],\"center\":[{\"id\":\"1114\"},{\"id\":\"1118\"}],\"left\":[{\"id\":\"1115\"}],\"plot_height\":300,\"plot_width\":450,\"renderers\":[{\"id\":\"1137\"},{\"id\":\"1215\"}],\"title\":{\"id\":\"1148\"},\"toolbar\":{\"id\":\"1126\"},\"x_range\":{\"id\":\"1103\"},\"x_scale\":{\"id\":\"1107\"},\"y_range\":{\"id\":\"1105\"},\"y_scale\":{\"id\":\"1109\"}},\"id\":\"1102\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"num_minor_ticks\":10},\"id\":\"1112\",\"type\":\"LogTicker\"},{\"attributes\":{},\"id\":\"1122\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis_label\":\"normalized GFP expression (a.u.)\",\"formatter\":{\"id\":\"1153\"},\"ticker\":{\"id\":\"1116\"}},\"id\":\"1115\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1115\"},\"dimension\":1,\"ticker\":null},\"id\":\"1118\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1234\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1107\",\"type\":\"LogScale\"},{\"attributes\":{\"axis\":{\"id\":\"1111\"},\"ticker\":null},\"id\":\"1114\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1119\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1133\"},\"glyph\":{\"id\":\"1135\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1136\"},\"selection_glyph\":null,\"view\":{\"id\":\"1138\"}},\"id\":\"1137\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1135\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1105\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1136\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1235\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"[IPTG] (mM)\":{\"__ndarray__\":\"/Knx0k1iUD97FK5H4XqEP3sUrkfhepQ/uB6F61G4nj97FK5H4XqkP3sUrkfheqQ/uB6F61G4rj+amZmZmZm5PzMzMzMzM9M/MzMzMzMz4z8AAAAAAADwPwAAAAAAAAhAAAAAAAAAGEAAAAAAAAAkQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],\"normalized GFP expression (a.u.)\":{\"__ndarray__\":\"VKnZA63AcD+pE9BE2PCEP9NIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP36kiAyr+O0/b9i2KLPB7j/SV5BmLBruP3i8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1haRuo9lXM/+n5qvHSTaD/CUl3Aywx7P6inj8AffrY/a9PYXgt6pz+D/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyiDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1154\"},\"selection_policy\":{\"id\":\"1155\"}},\"id\":\"1133\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data\":{\"[IPTG] (mM)\":{\"__ndarray__\":\"/Knx0k1iUD97FK5H4XqEP3sUrkfhepQ/uB6F61G4nj97FK5H4XqkP3sUrkfheqQ/uB6F61G4rj+amZmZmZm5PzMzMzMzM9M/MzMzMzMz4z8AAAAAAADwPwAAAAAAAAhAAAAAAAAAGEAAAAAAAAAkQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"error_high\":{\"__ndarray__\":\"4xbzc0NThj9s1pWmcwuOP7XWH3q1UKA/Oul942vPpD8UiXQF/Ja0Py7iXD/U6Oo/8rsjQqeQ6j/pQDl+ZpjuPzBQxrYUqe8/ME4Zi+hP8j+55NlhIzvwP0xyZfWz/e4/6+TKqEsp8D+xLvLbpUfvPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"error_low\":{\"__ndarray__\":\"PLZlwFlKZr/NoRTGeax3P3nIrazh4Io/MT1hiQeUnT9UyPik0eyrP7znflayxt8/OjbIRTHQ5D8VBCxFNDLnP8z4SmJBSOw/fhQ7O5Xj6D8z5mwJEr7rP6QGLurulec/9WMXNS3r6T+zTDsMGOrpPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],\"normalized GFP expression (a.u.)\":{\"__ndarray__\":\"VKnZA63AcD+pE9BE2PCEP9NIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP36kiAyr+O0/b9i2KLPB7j/SV5BmLBruP3i8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1haRuo9lXM/+n5qvHSTaD/CUl3Aywx7P6inj8AffrY/a9PYXgt6pz+D/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyiDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1234\"},\"selection_policy\":{\"id\":\"1235\"}},\"id\":\"1211\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"1133\"}},\"id\":\"1138\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1116\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis_label\":\"[IPTG] (mM)\",\"formatter\":{\"id\":\"1151\"},\"ticker\":{\"id\":\"1112\"}},\"id\":\"1111\",\"type\":\"LogAxis\"},{\"attributes\":{\"source\":{\"id\":\"1211\"}},\"id\":\"1216\",\"type\":\"CDSView\"},{\"attributes\":{\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":2},\"x0\":{\"field\":\"[IPTG] (mM)\"},\"x1\":{\"field\":\"[IPTG] (mM)\"},\"y0\":{\"field\":\"error_low\"},\"y1\":{\"field\":\"error_high\"}},\"id\":\"1213\",\"type\":\"Segment\"},{\"attributes\":{\"overlay\":{\"id\":\"1125\"}},\"id\":\"1121\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1148\",\"type\":\"Title\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":2},\"x0\":{\"field\":\"[IPTG] (mM)\"},\"x1\":{\"field\":\"[IPTG] (mM)\"},\"y0\":{\"field\":\"error_low\"},\"y1\":{\"field\":\"error_high\"}},\"id\":\"1214\",\"type\":\"Segment\"},{\"attributes\":{},\"id\":\"1103\",\"type\":\"DataRange1d\"},{\"attributes\":{\"ticker\":null},\"id\":\"1151\",\"type\":\"LogTickFormatter\"},{\"attributes\":{},\"id\":\"1155\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1154\",\"type\":\"Selection\"},{\"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,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1125\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1119\"},{\"id\":\"1120\"},{\"id\":\"1121\"},{\"id\":\"1122\"},{\"id\":\"1123\"},{\"id\":\"1124\"}]},\"id\":\"1126\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1109\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1120\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1211\"},\"glyph\":{\"id\":\"1213\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1214\"},\"selection_glyph\":null,\"view\":{\"id\":\"1216\"}},\"id\":\"1215\",\"type\":\"GlyphRenderer\"}],\"root_ids\":[\"1102\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n", " var render_items = [{\"docid\":\"266febba-0f33-4ab0-9660-e4ea5678ee70\",\"root_ids\":[\"1102\"],\"roots\":{\"1102\":\"6ff01ee6-ca0b-45d6-856d-29093d9babbf\"}}];\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": "1102" } }, "output_type": "display_data" } ], "source": [ "# Add error bars\n", "p.segment(\n", " source=df,\n", " x0=x,\n", " y0='error_low',\n", " x1=x,\n", " y1='error_high',\n", " line_width=2,\n", ")\n", "\n", "bokeh.io.show(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the interactivity, you can zoom in on the point with the smalled IPTG concentration. Note the value of interactive graphics here. Even though the error bar is smaller than the dot on the zoomed-out plot, it is resolvable upon zooming in, which is impossible even with vector graphics. Note also a common problem with using an s.e.m. to compute error bars. The result is something unphysical; the error bar extends below zero. In general using s.e.m. for error bars is a not a good idea, and we will cover better ways of computing error bars when we discuss hacker stats in upcoming lessons." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Computing environment" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPython 3.7.7\n", "IPython 7.16.1\n", "\n", "pandas 0.24.2\n", "bokeh 2.1.1\n", "jupyterlab 2.1.5\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark -v -p pandas,bokeh,jupyterlab" ] } ], "metadata": { "anaconda-cloud": {}, "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.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }