{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Get import" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from drawnmr import draw\n", "import nmrglue as ng\n", "import bokeh.plotting as bplt\n", "from bokeh.models import Range1d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get data" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Get data\n", "import os, os.path\n", "ng_dir = 'nmrglue_data/s4_2d_plotting'\n", "if not os.path.exists(ng_dir):\n", " print(\"No %s. Downloading.\"%ng_dir)\n", " import urllib.request, zipfile\n", " zipf = 'jbnmr_s4_2d_plotting.zip'\n", " urllib.request.urlretrieve('https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/nmrglue/%s'%zipf, zipf)\n", " with zipfile.ZipFile(zipf,\"r\") as zip_ref:\n", " zip_ref.extractall(\"nmrglue_data\")\n", " os.remove(zipf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Read data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Specify data\n", "ng_ft2 = 'nmrglue_data/s4_2d_plotting/test.ft2'\n", "\n", "# read in data\n", "ng_dic, ng_data = ng.pipe.read(ng_ft2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Create figure" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Pass to figure class\n", "fig2d = draw.fig2d(ng_dic, ng_data)\n", "# Change contour_start\n", "fig2d.contour_start = 85e3\n", "\n", "# Get the bokeh figure\n", "fig= fig2d.get_fig()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Alter figure" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Alter the figure after creation\n", "#fig.xaxis.axis_label = \"Nonsense\"\n", "\n", "# Set limits for view\n", "fig.x_range = Range1d(183.5, 167.5)\n", "fig.y_range = Range1d(139.5, 95.5)\n", "\n", "# Set larger image size\n", "fig.plot_width = 600\n", "fig.plot_height = 600" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get widget" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Get widget\n", "contour_widget = fig2d.get_contour_widget()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Show output" ] }, { "cell_type": "code", "execution_count": 7, "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", "\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", " if (root.Bokeh !== undefined) {\n", " var el = document.getElementById(\"b98be8fd-259d-41b4-aa05-36e8d354c328\");\n", " if (el != null) {\n", " el.textContent = \"BokehJS \" + Bokeh.version + \" successfully loaded.\";\n", " }\n", " } else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(display_loaded, 100)\n", " }\n", " }\n", "\n", "\n", " function run_callbacks() {\n", " try {\n", " root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " }\n", " finally {\n", " delete root._bokeh_onload_callbacks\n", " }\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " root._bokeh_onload_callbacks.push(callback);\n", " if (root._bokeh_is_loading > 0) {\n", " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " root._bokeh_is_loading = js_urls.length;\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var s = document.createElement('script');\n", " s.src = url;\n", " s.async = false;\n", " s.onreadystatechange = s.onload = function() {\n", " root._bokeh_is_loading--;\n", " if (root._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", " run_callbacks()\n", " }\n", " };\n", " s.onerror = function() {\n", " console.warn(\"failed to load library \" + url);\n", " };\n", " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " }\n", " };var element = document.getElementById(\"b98be8fd-259d-41b4-aa05-36e8d354c328\");\n", " if (element == null) {\n", " console.log(\"Bokeh: ERROR: autoload.js configured with elementid 'b98be8fd-259d-41b4-aa05-36e8d354c328' but no matching script tag was found. \")\n", " return false;\n", " }\n", "\n", " var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.7.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.7.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.7.min.js\"];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " \n", " },\n", " \n", " function(Bokeh) {\n", " \n", " document.getElementById(\"b98be8fd-259d-41b4-aa05-36e8d354c328\").textContent = \"BokehJS is loading...\";\n", "\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.7.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.7.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.7.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.7.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " \n", " if ((root.Bokeh !== undefined) || (force === true)) {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i].call(root, root.Bokeh);\n", " }if (force === true) {\n", " display_loaded();\n", " }} else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!root._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " root._bokeh_failed_load = true;\n", " } else if (force !== true) {\n", " var cell = $(document.getElementById(\"b98be8fd-259d-41b4-aa05-36e8d354c328\")).parents('.cell').data().cell;\n", " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", " }\n", "\n", " }\n", "\n", " if (root._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(js_urls, function() {\n", " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(window));" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "98b0181b31004dae8338f5fd0eed4e55", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type VBox.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "VBox(children=(Label(value='Settings for contour:'), HBox(children=(FloatText(value=85000.0, description='start:'), IntText(value=20, description='num:'), FloatText(value=1.2, description='factor:')))))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Get output. Either to Jupyter notebook or html file \n", "if fig2d.isnotebook:\n", " from bokeh.io import output_notebook\n", " output_notebook()\n", " bplt.show(fig, notebook_handle=True)\n", " display(contour_widget)\n", "else:\n", " # Save to html\n", " filename = \"nmrglue_s4_2d_plotting.html\"\n", " bplt.output_file(filename)\n", " bplt.save(fig)\n", " # And auto open\n", " import webbrowser, os\n", " webbrowser.open('file://' + os.path.realpath(filename))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Change graph upon modification of contour_start" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "#fig2d.change_contour_start(200e3)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "21afed0d4b174930b4fbfe9abef13ac1": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "FloatTextModel", "state": { "description": "start:", "layout": "IPY_MODEL_efda2bd118754e638ed61ea1e64596ea", "step": null, "style": "IPY_MODEL_4f9105781ed4496084f5e96596d148dd", "value": 50000 } }, "35987a0418c640a09a394be5e7431f56": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.0.0", "model_name": "LayoutModel", "state": {} }, "3ff40da2874945a29b5a1a1d7dc28415": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "HBoxModel", "state": { "children": [ "IPY_MODEL_21afed0d4b174930b4fbfe9abef13ac1", "IPY_MODEL_e3b6383faafe4ecfad0c666c8d7222b8", "IPY_MODEL_fdadb7e57f0f4c1ca737a9c3970c6229" ], "layout": "IPY_MODEL_57f164cfcce847a98517d6afea8d44b9" } }, "4f9105781ed4496084f5e96596d148dd": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "57f164cfcce847a98517d6afea8d44b9": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.0.0", "model_name": "LayoutModel", "state": {} }, "654279c13a3b4dd79e20eec14e30d7b1": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.0.0", "model_name": "LayoutModel", "state": {} }, "7c7d4b5cbd184d3e94022b0f548c7273": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "LabelModel", "state": { "layout": "IPY_MODEL_c0c4476d9b074b9e9ff038538d4809f8", "style": "IPY_MODEL_93908ee9e2564e01bfba2f843f7ab0cb", "value": "Settings for contour:" } }, "93908ee9e2564e01bfba2f843f7ab0cb": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "98b0181b31004dae8338f5fd0eed4e55": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "VBoxModel", "state": { "children": [ "IPY_MODEL_7c7d4b5cbd184d3e94022b0f548c7273", "IPY_MODEL_3ff40da2874945a29b5a1a1d7dc28415" ], "layout": "IPY_MODEL_35987a0418c640a09a394be5e7431f56" } }, "c0c4476d9b074b9e9ff038538d4809f8": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.0.0", "model_name": "LayoutModel", "state": {} }, "ced098820fdc44fbb894d14ecf0d06ec": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.0.0", "model_name": "LayoutModel", "state": {} }, "cee8ec4c7b274331a51bef26fa73daf8": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "e3b6383faafe4ecfad0c666c8d7222b8": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "IntTextModel", "state": { "description": "num:", "layout": "IPY_MODEL_654279c13a3b4dd79e20eec14e30d7b1", "step": 1, "style": "IPY_MODEL_cee8ec4c7b274331a51bef26fa73daf8", "value": 15 } }, "efda2bd118754e638ed61ea1e64596ea": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.0.0", "model_name": "LayoutModel", "state": {} }, "f9183c3b93bc4442a50752a394cc7f35": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "fdadb7e57f0f4c1ca737a9c3970c6229": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.0.0", "model_name": "FloatTextModel", "state": { "description": "factor:", "layout": "IPY_MODEL_ced098820fdc44fbb894d14ecf0d06ec", "step": null, "style": "IPY_MODEL_f9183c3b93bc4442a50752a394cc7f35", "value": 1.1 } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }