{ "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", "
" ] }, "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", " \"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",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"Failed to display Jupyter Widget of type VBox
.
\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 }