{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercise 3.4: 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", "**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", " const 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", " const JS_MIME_TYPE = 'application/javascript';\n", " const HTML_MIME_TYPE = 'text/html';\n", " const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n", " const CLASS_NAME = 'output_bokeh rendered_html';\n", "\n", " /**\n", " * Render data to the DOM node\n", " */\n", " function render(props, node) {\n", " const 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", " const cell = handle.cell;\n", "\n", " const id = cell.output_area._bokeh_element_id;\n", " const 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", " const cmd_clean = \"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_clean, {\n", " iopub: {\n", " output: function(msg) {\n", " const 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", " const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n", " cell.notebook.kernel.execute(cmd_destroy);\n", " }\n", " }\n", "\n", " /**\n", " * Handle when a new output is added\n", " */\n", " function handleAddOutput(event, handle) {\n", " const output_area = handle.output_area;\n", " const output = handle.output;\n", "\n", " // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n", " if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n", " return\n", " }\n", "\n", " const 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", " const bk_div = document.createElement(\"div\");\n", " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", " const script_attrs = bk_div.children[0].attributes;\n", " for (let 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", " const 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", " const 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", " const events = require('base/js/events');\n", " const 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", " const 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", " const el = document.getElementById(\"1002\");\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(url) {\n", " console.error(\"failed to load \" + url);\n", " }\n", "\n", " for (let i = 0; i < css_urls.length; i++) {\n", " const url = css_urls[i];\n", " const element = document.createElement(\"link\");\n", " element.onload = on_load;\n", " element.onerror = on_error.bind(null, url);\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", " for (let i = 0; i < js_urls.length; i++) {\n", " const url = js_urls[i];\n", " const element = document.createElement('script');\n", " element.onload = on_load;\n", " element.onerror = on_error.bind(null, url);\n", " element.async = false;\n", " element.src = url;\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", " const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n", " const css_urls = [];\n", " \n", "\n", " const 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 (let 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", " const cell = $(document.getElementById(\"1002\")).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 const 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 const 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 const el = document.getElementById(\"1002\");\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(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\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 for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\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 const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n const css_urls = [];\n \n\n const 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 (let 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 const cell = $(document.getElementById(\"1002\")).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", " const docs_json = {\"83460875-c405-42c5-b983-e70a133b6eb1\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1012\"}],\"center\":[{\"id\":\"1015\"},{\"id\":\"1019\"}],\"frame_height\":300,\"frame_width\":450,\"left\":[{\"id\":\"1016\"}],\"renderers\":[{\"id\":\"1039\"}],\"title\":{\"id\":\"1041\"},\"toolbar\":{\"id\":\"1027\"},\"x_range\":{\"id\":\"1004\"},\"x_scale\":{\"id\":\"1008\"},\"y_range\":{\"id\":\"1006\"},\"y_scale\":{\"id\":\"1010\"}},\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"1026\"}},\"id\":\"1022\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1010\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis\":{\"id\":\"1016\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1019\",\"type\":\"Grid\"},{\"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+pE9BE2PCEP9RIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP3+kiAyr+O0/b9i2KLPB7j/RV5BmLBruP3e8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1daRuo9lXM/+n5qvHSTaD/BUl3Aywx7P6inj8AffrY/a9PYXgt6pz+C/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyeDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1050\"},\"selection_policy\":{\"id\":\"1049\"}},\"id\":\"1034\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1047\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1036\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1048\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1017\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1006\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1008\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1004\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1025\",\"type\":\"HelpTool\"},{\"attributes\":{\"axis_label\":\"[IPTG] (mM)\",\"coordinates\":null,\"formatter\":{\"id\":\"1047\"},\"group\":null,\"major_label_policy\":{\"id\":\"1048\"},\"ticker\":{\"id\":\"1013\"}},\"id\":\"1012\",\"type\":\"LinearAxis\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1026\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1034\"},\"glyph\":{\"id\":\"1036\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1038\"},\"nonselection_glyph\":{\"id\":\"1037\"},\"view\":{\"id\":\"1040\"}},\"id\":\"1039\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1037\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1049\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"tools\":[{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"},{\"id\":\"1025\"}]},\"id\":\"1027\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1013\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1050\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1021\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1012\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1015\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1038\",\"type\":\"Circle\"},{\"attributes\":{\"source\":{\"id\":\"1034\"}},\"id\":\"1040\",\"type\":\"CDSView\"},{\"attributes\":{\"axis_label\":\"normalized GFP expression (a.u.)\",\"coordinates\":null,\"formatter\":{\"id\":\"1044\"},\"group\":null,\"major_label_policy\":{\"id\":\"1045\"},\"ticker\":{\"id\":\"1017\"}},\"id\":\"1016\",\"type\":\"LinearAxis\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1041\",\"type\":\"Title\"}],\"root_ids\":[\"1003\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n", " const render_items = [{\"docid\":\"83460875-c405-42c5-b983-e70a133b6eb1\",\"root_ids\":[\"1003\"],\"roots\":{\"1003\":\"9f451a16-925c-411e-adb3-fa85db664bd3\"}}];\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", " let attempts = 0;\n", " const 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": "1003" } }, "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", " const docs_json = {\"bad8c961-d1e5-4134-a331-3b665b008ff9\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1116\"}],\"center\":[{\"id\":\"1119\"},{\"id\":\"1123\"}],\"height\":300,\"left\":[{\"id\":\"1120\"}],\"renderers\":[{\"id\":\"1143\"}],\"title\":{\"id\":\"1156\"},\"toolbar\":{\"id\":\"1131\"},\"width\":450,\"x_range\":{\"id\":\"1108\"},\"x_scale\":{\"id\":\"1112\"},\"y_range\":{\"id\":\"1110\"},\"y_scale\":{\"id\":\"1114\"}},\"id\":\"1107\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1125\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"tools\":[{\"id\":\"1124\"},{\"id\":\"1125\"},{\"id\":\"1126\"},{\"id\":\"1127\"},{\"id\":\"1128\"},{\"id\":\"1129\"}]},\"id\":\"1131\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"1116\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1119\",\"type\":\"Grid\"},{\"attributes\":{\"num_minor_ticks\":10},\"id\":\"1117\",\"type\":\"LogTicker\"},{\"attributes\":{},\"id\":\"1114\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1159\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis_label\":\"[IPTG] (mM)\",\"coordinates\":null,\"formatter\":{\"id\":\"1162\"},\"group\":null,\"major_label_policy\":{\"id\":\"1163\"},\"ticker\":{\"id\":\"1117\"}},\"id\":\"1116\",\"type\":\"LogAxis\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1138\"},\"glyph\":{\"id\":\"1140\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1142\"},\"nonselection_glyph\":{\"id\":\"1141\"},\"view\":{\"id\":\"1144\"}},\"id\":\"1143\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis_label\":\"normalized GFP expression (a.u.)\",\"coordinates\":null,\"formatter\":{\"id\":\"1159\"},\"group\":null,\"major_label_policy\":{\"id\":\"1160\"},\"ticker\":{\"id\":\"1121\"}},\"id\":\"1120\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1120\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1123\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1142\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1163\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1129\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1141\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1130\"}},\"id\":\"1126\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1112\",\"type\":\"LogScale\"},{\"attributes\":{},\"id\":\"1127\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1128\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1165\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1110\",\"type\":\"DataRange1d\"},{\"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+pE9BE2PCEP9RIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP3+kiAyr+O0/b9i2KLPB7j/RV5BmLBruP3e8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1daRuo9lXM/+n5qvHSTaD/BUl3Aywx7P6inj8AffrY/a9PYXgt6pz+C/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyeDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1165\"},\"selection_policy\":{\"id\":\"1164\"}},\"id\":\"1138\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1130\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1160\",\"type\":\"AllLabels\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1140\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1164\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"ticker\":null},\"id\":\"1162\",\"type\":\"LogTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1156\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"1138\"}},\"id\":\"1144\",\"type\":\"CDSView\"}],\"root_ids\":[\"1107\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n", " const render_items = [{\"docid\":\"bad8c961-d1e5-4134-a331-3b665b008ff9\",\"root_ids\":[\"1107\"],\"roots\":{\"1107\":\"0586ebf0-ec29-4105-a3c1-0d6db0b7ab3b\"}}];\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", " let attempts = 0;\n", " const 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": "1107" } }, "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", " const docs_json = {\"81442638-2334-4457-9ce5-9428dde4a79e\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1116\"}],\"center\":[{\"id\":\"1119\"},{\"id\":\"1123\"}],\"height\":300,\"left\":[{\"id\":\"1120\"}],\"renderers\":[{\"id\":\"1143\"},{\"id\":\"1227\"}],\"title\":{\"id\":\"1156\"},\"toolbar\":{\"id\":\"1131\"},\"width\":450,\"x_range\":{\"id\":\"1108\"},\"x_scale\":{\"id\":\"1112\"},\"y_range\":{\"id\":\"1110\"},\"y_scale\":{\"id\":\"1114\"}},\"id\":\"1107\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"source\":{\"id\":\"1222\"}},\"id\":\"1228\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1125\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"tools\":[{\"id\":\"1124\"},{\"id\":\"1125\"},{\"id\":\"1126\"},{\"id\":\"1127\"},{\"id\":\"1128\"},{\"id\":\"1129\"}]},\"id\":\"1131\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"1116\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1119\",\"type\":\"Grid\"},{\"attributes\":{\"num_minor_ticks\":10},\"id\":\"1117\",\"type\":\"LogTicker\"},{\"attributes\":{},\"id\":\"1114\",\"type\":\"LinearScale\"},{\"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\":\"1225\",\"type\":\"Segment\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1159\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis_label\":\"[IPTG] (mM)\",\"coordinates\":null,\"formatter\":{\"id\":\"1162\"},\"group\":null,\"major_label_policy\":{\"id\":\"1163\"},\"ticker\":{\"id\":\"1117\"}},\"id\":\"1116\",\"type\":\"LogAxis\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1138\"},\"glyph\":{\"id\":\"1140\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1142\"},\"nonselection_glyph\":{\"id\":\"1141\"},\"view\":{\"id\":\"1144\"}},\"id\":\"1143\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis_label\":\"normalized GFP expression (a.u.)\",\"coordinates\":null,\"formatter\":{\"id\":\"1159\"},\"group\":null,\"major_label_policy\":{\"id\":\"1160\"},\"ticker\":{\"id\":\"1121\"}},\"id\":\"1120\",\"type\":\"LinearAxis\"},{\"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\":\"1224\",\"type\":\"Segment\"},{\"attributes\":{\"axis\":{\"id\":\"1120\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1123\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1250\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1142\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1163\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1129\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1141\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1251\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"1130\"}},\"id\":\"1126\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1222\"},\"glyph\":{\"id\":\"1224\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1226\"},\"nonselection_glyph\":{\"id\":\"1225\"},\"view\":{\"id\":\"1228\"}},\"id\":\"1227\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1112\",\"type\":\"LogScale\"},{\"attributes\":{},\"id\":\"1127\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1128\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1165\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1110\",\"type\":\"DataRange1d\"},{\"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+pE9BE2PCEP9RIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP3+kiAyr+O0/b9i2KLPB7j/RV5BmLBruP3e8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1daRuo9lXM/+n5qvHSTaD/BUl3Aywx7P6inj8AffrY/a9PYXgt6pz+C/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyeDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1165\"},\"selection_policy\":{\"id\":\"1164\"}},\"id\":\"1138\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"line_alpha\":{\"value\":0.2},\"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\":\"1226\",\"type\":\"Segment\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1130\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1160\",\"type\":\"AllLabels\"},{\"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+ZpjuPzFQxrYUqe8/ME4Zi+hP8j+45NlhIzvwP0pyZfWz/e4/6+TKqEsp8D+xLvLbpUfvPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"error_low\":{\"__ndarray__\":\"PLZlwFlKZr/NoRTGeax3P3zIrazh4Io/MT1hiQeUnT9UyPik0eyrP7znflayxt8/OjbIRTHQ5D8VBCxFNDLnP834SmJBSOw/fhQ7O5Xj6D8y5mwJEr7rP6QGLurulec/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+pE9BE2PCEP9RIS+XtCJc/6UMX1LfMoT+fdvhrskaxPwYrTrUWZuU/Fvn1Q2yw5z9/orJhTeXqP3+kiAyr+O0/b9i2KLPB7j/RV5BmLBruP3e8yW/RSes/5pZWQ+Ie7T+yvRb03pjsPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]},\"sem\":{\"__ndarray__\":\"8rBQa5p3bD+SeHk6V5RiP1daRuo9lXM/+n5qvHSTaD/BUl3Aywx7P6inj8AffrY/a9PYXgt6pz+C/de5aTOuP7WK/tDMk5s/AFRx4xbztz9x4xbzc0OjPyeDo+TVOa4/0nDK3Hwjqj/HuU24V+alPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[14]}},\"selected\":{\"id\":\"1251\"},\"selection_policy\":{\"id\":\"1250\"}},\"id\":\"1222\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"[IPTG] (mM)\"},\"y\":{\"field\":\"normalized GFP expression (a.u.)\"}},\"id\":\"1140\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1164\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"ticker\":null},\"id\":\"1162\",\"type\":\"LogTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1156\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"1138\"}},\"id\":\"1144\",\"type\":\"CDSView\"}],\"root_ids\":[\"1107\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n", " const render_items = [{\"docid\":\"81442638-2334-4457-9ce5-9428dde4a79e\",\"root_ids\":[\"1107\"],\"roots\":{\"1107\":\"e69e930c-6799-4a1d-b3f1-498bb80bda4e\"}}];\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", " let attempts = 0;\n", " const 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": "1107" } }, "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": { "tags": [ "hide-input" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python implementation: CPython\n", "Python version : 3.9.12\n", "IPython version : 8.3.0\n", "\n", "pandas : 1.4.2\n", "bokeh : 2.4.2\n", "jupyterlab: 3.3.2\n", "\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark -v -p pandas,bokeh,jupyterlab" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.12" } }, "nbformat": 4, "nbformat_minor": 4 }