From 510bfa9538817ce99fece2854149ae0ee80a4779 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Tue, 20 Mar 2018 11:12:51 +0100 Subject: [PATCH] make plot by id take a axes argument for easier embedding (#1006) * make plot by id take a axes argument for easier embedding * missed this one * support plotting more than one dataset from each scan * update context manager notebook * add missing return * Rerun plotting notebook * fix return name * better wording of error message --- .../DataSet/Dataset Context Manager.ipynb | 290 ++--- .../DataSet/Testing quick plotting.ipynb | 1101 ++++++++++++++--- qcodes/dataset/plotting.py | 54 +- 3 files changed, 1117 insertions(+), 328 deletions(-) diff --git a/docs/examples/DataSet/Dataset Context Manager.ipynb b/docs/examples/DataSet/Dataset Context Manager.ipynb index a5b17b1c05f..a462658eb76 100644 --- a/docs/examples/DataSet/Dataset Context Manager.ipynb +++ b/docs/examples/DataSet/Dataset Context Manager.ipynb @@ -13,9 +13,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "%matplotlib notebook\n", @@ -46,9 +44,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# a generator to simulate a physical signal, in this case an exponentially\n", @@ -67,9 +63,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# preparatory mocking of physical setup\n", @@ -83,9 +77,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# and then a bit of \"wiring\" to make the dmm \"measure\"\n", @@ -105,9 +97,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# now make some silly set-up and tear-down actions\n", @@ -135,7 +125,7 @@ "text": [ "Starting the measurement\n", "Doing stuff with the following two instruments: , \n", - "Starting experimental run with id: 89\n", + "Starting experimental run with id: 1048\n", "End of experiment\n" ] } @@ -251,7 +241,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -746,7 +736,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -898,9 +888,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -949,7 +942,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -960,7 +953,7 @@ } ], "source": [ - "fig = plot_by_id(dataid)" + "ax = plot_by_id(dataid)" ] }, { @@ -983,7 +976,7 @@ "text": [ "Starting the measurement\n", "Doing stuff with the following two instruments: , \n", - "Starting experimental run with id: 90\n", + "Starting experimental run with id: 1049\n", "End of experiment\n" ] } @@ -1095,7 +1088,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -1590,7 +1583,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -1742,9 +1735,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -1793,7 +1789,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -1804,12 +1800,12 @@ } ], "source": [ - "fig = plot_by_id(dataid)" + "ax = plot_by_id(dataid)" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -1818,7 +1814,7 @@ "text": [ "Starting the measurement\n", "Doing stuff with the following two instruments: , \n", - "Starting experimental run with id: 91\n", + "Starting experimental run with id: 1045\n", "End of experiment\n" ] } @@ -1849,7 +1845,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -1934,7 +1930,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -2429,7 +2425,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -2581,9 +2577,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -2632,7 +2631,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -2643,12 +2642,12 @@ } ], "source": [ - "fig = plot_by_id(dataid)\n", + "axes = plot_by_id(dataid)\n", "# we slightly tweak the plot to better visualise the highly non-standard axis spacing\n", - "fig.axes[0].lines[0].set_marker('o')\n", - "fig.axes[0].lines[0].set_markerfacecolor((0.6, 0.6, 0.9))\n", - "fig.axes[0].lines[0].set_markeredgecolor((0.4, 0.6, 0.9))\n", - "fig.axes[0].lines[0].set_color((0.8, 0.8, 0.8))" + "axes[0].lines[0].set_marker('o')\n", + "axes[0].lines[0].set_markerfacecolor((0.6, 0.6, 0.9))\n", + "axes[0].lines[0].set_markeredgecolor((0.4, 0.6, 0.9))\n", + "axes[0].lines[0].set_color((0.8, 0.8, 0.8))" ] }, { @@ -2660,10 +2659,8 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": true - }, + "execution_count": 11, + "metadata": {}, "outputs": [], "source": [ "# For the 2D, we'll need a new batch of parameters, notably one with two \n", @@ -2678,10 +2675,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": true - }, + "execution_count": 12, + "metadata": {}, "outputs": [], "source": [ "# and we'll make a 2D gaussian to sample from/measure\n", @@ -2699,10 +2694,8 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": { - "collapsed": true - }, + "execution_count": 13, + "metadata": {}, "outputs": [], "source": [ "# and finally wire up the dmm v1 to \"measure\" the gaussian\n", @@ -2720,14 +2713,14 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 92\n" + "Starting experimental run with id: 1050\n" ] } ], @@ -2750,7 +2743,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -2835,7 +2828,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -3330,7 +3323,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -3482,9 +3475,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -3533,7 +3529,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -3544,19 +3540,19 @@ } ], "source": [ - "fig = plot_by_id(dataid)" + "ax = plot_by_id(dataid)" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 93\n" + "Starting experimental run with id: 1051\n" ] } ], @@ -3587,7 +3583,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -3672,7 +3668,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -4167,7 +4163,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -4319,9 +4315,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -4370,7 +4369,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -4381,19 +4380,19 @@ } ], "source": [ - "fig = plot_by_id(dataid)" + "ax = plot_by_id(dataid)" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 94\n", + "Starting experimental run with id: 1052\n", "130 46 0.25089416831\n", "----------\n" ] @@ -4460,7 +4459,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -4545,7 +4544,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -5040,7 +5039,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -5192,9 +5191,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -5243,7 +5245,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -5254,7 +5256,7 @@ } ], "source": [ - "fig = plot_by_id(dataid)" + "ax = plot_by_id(dataid)" ] }, { @@ -5275,10 +5277,8 @@ }, { "cell_type": "code", - "execution_count": 21, - "metadata": { - "collapsed": true - }, + "execution_count": 20, + "metadata": {}, "outputs": [], "source": [ "gauss = gauss_model(0.1, 0.2, 0.25)\n", @@ -5293,14 +5293,14 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 95\n" + "Starting experimental run with id: 1053\n" ] } ], @@ -5325,16 +5325,9 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2D data does not seem to be on a grid. Falling back to scatter plot\n" - ] - }, { "data": { "application/javascript": [ @@ -5417,7 +5410,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -5912,7 +5905,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -6064,9 +6057,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -6115,7 +6111,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -6123,10 +6119,17 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2D data does not seem to be on a grid. Falling back to scatter plot\n" + ] } ], "source": [ - "fig = plot_by_id(dataid)" + "ax = plot_by_id(dataid)" ] }, { @@ -6145,10 +6148,8 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": true - }, + "execution_count": 23, + "metadata": {}, "outputs": [], "source": [ "from scipy.optimize import minimize" @@ -6156,10 +6157,8 @@ }, { "cell_type": "code", - "execution_count": 25, - "metadata": { - "collapsed": true - }, + "execution_count": 24, + "metadata": {}, "outputs": [], "source": [ "noise = 0.0005\n", @@ -6175,14 +6174,14 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 96\n" + "Starting experimental run with id: 1054\n" ] } ], @@ -6202,7 +6201,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -6211,16 +6210,16 @@ " final_simplex: (array([[ 0.1, 0.2],\n", " [ 0.1, 0.2],\n", " [ 0.1, 0.2]]), array([-1.13314845, -1.13314845, -1.13314845]))\n", - " fun: -1.1331484530668263\n", + " fun: -1.1331484530668261\n", " message: 'Optimization terminated successfully.'\n", - " nfev: 155\n", - " nit: 76\n", + " nfev: 153\n", + " nit: 74\n", " status: 0\n", " success: True\n", " x: array([ 0.1, 0.2])" ] }, - "execution_count": 27, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -6234,13 +6233,6 @@ "execution_count": 28, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2D data does not seem to be on a grid. Falling back to scatter plot\n" - ] - }, { "data": { "application/javascript": [ @@ -6323,7 +6315,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -6818,7 +6810,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -6970,9 +6962,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -7021,7 +7016,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -7029,10 +7024,17 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2D data does not seem to be on a grid. Falling back to scatter plot\n" + ] } ], "source": [ - "plot_by_id(run_id)" + "ax = plot_by_id(run_id)" ] }, { @@ -7059,14 +7061,14 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 98\n", + "Starting experimental run with id: 1055\n", "Added points to measurement, step 0.\n", "Added points to measurement, step 1.\n", "The run now holds 3 rows\n", @@ -7078,7 +7080,7 @@ "The run now holds 7 rows\n", "Added points to measurement, step 6.\n", "Added points to measurement, step 7.\n", - "The run now holds 8 rows\n", + "The run now holds 9 rows\n", "Added points to measurement, step 8.\n", "Added points to measurement, step 9.\n", "The run now holds 10 rows\n" @@ -7122,14 +7124,14 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting experimental run with id: 99\n", + "Starting experimental run with id: 1056\n", "Added points to measurement, step 0.\n", "First parameter value list: []\n", "Added points to measurement, step 1.\n", @@ -7144,7 +7146,7 @@ "First parameter value list: [0, 1, 2, 3, 4]\n", "Added points to measurement, step 5.\n", "First parameter value list: [0, 1, 2, 3, 4]\n", - "The run now holds 6 rows\n", + "The run now holds 7 rows\n", "Added points to measurement, step 6.\n", "First parameter value list: [0, 1, 2, 3, 4, 5, 6]\n", "Added points to measurement, step 7.\n", @@ -7214,7 +7216,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.0" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/docs/examples/DataSet/Testing quick plotting.ipynb b/docs/examples/DataSet/Testing quick plotting.ipynb index 1b00ec68b43..815214b9715 100644 --- a/docs/examples/DataSet/Testing quick plotting.ipynb +++ b/docs/examples/DataSet/Testing quick plotting.ipynb @@ -30,9 +30,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# if you just deleted your database file, you'll need to init a new one\n", @@ -49,8 +47,8 @@ { "data": { "text/plain": [ - "test_plot_by_id#nosample#9@./experiments.db\n", - "-------------------------------------------" + "test_plot_by_id#nosample#64@./experiments.db\n", + "--------------------------------------------" ] }, "execution_count": 3, @@ -65,9 +63,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Make a handful of parameters to be used in the examples\n", @@ -89,9 +85,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "data_set = new_data_set('1D-sweep')" @@ -100,9 +94,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "data_set.add_parameter(x)\n", @@ -112,9 +104,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "xvals = np.linspace(-3.4, 4.2, 250)\n", @@ -211,7 +201,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -706,7 +696,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -858,9 +848,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -909,7 +902,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -935,9 +928,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "data_set = new_data_set('interleaved-1Ds')" @@ -946,9 +937,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "data_set.add_parameter(x)\n", @@ -959,9 +948,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "xvals = np.linspace(-5, 5, 250)\n", @@ -974,7 +961,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -1059,7 +1046,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -1554,7 +1541,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -1706,9 +1693,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -1757,7 +1747,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -1765,60 +1755,7 @@ }, "metadata": {}, "output_type": "display_data" - } - ], - "source": [ - "plot = plot_by_id(data_set.run_id)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "## Regular 2D rectangular sweep scan" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "data_set = new_data_set('regular-2D-scan')\n", - "data_set.add_parameter(x)\n", - "data_set.add_parameter(t)\n", - "data_set.add_parameter(z)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "xvals = np.linspace(-4, 5, 50)\n", - "tvals = np.linspace(-500, 1500, 25)\n", - "\n", - "for xv in xvals:\n", - " for tv in tvals:\n", - " # just some arbitrary semi good looking function\n", - " zv = np.sin(2*np.pi*xv)*np.cos(2*np.pi*0.001*tv) + 0.001*tv\n", - " data_set.add_result({'x': xv, 't': tv, 'z': zv})\n", - "\n", - "data_set.mark_complete()" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ + }, { "data": { "application/javascript": [ @@ -1901,7 +1838,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -2396,7 +2333,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -2548,9 +2485,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -2599,7 +2539,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -2615,23 +2555,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "collapsed": true + }, "source": [ - "## Warped 2D rectangular sweep scan\n", - "\n", - "A nice feature of the new dataset is that the grid may be warped; it makes no difference.\n", - "Here we warp the x axis of the previous scan to increase the resolution in the right half plane." + "## Regular 2D rectangular sweep scan" ] }, { "cell_type": "code", - "execution_count": 18, - "metadata": { - "collapsed": true - }, + "execution_count": 13, + "metadata": {}, "outputs": [], "source": [ - "data_set = new_data_set('warped-2D-scan')\n", + "data_set = new_data_set('regular-2D-scan')\n", "data_set.add_parameter(x)\n", "data_set.add_parameter(t)\n", "data_set.add_parameter(z)" @@ -2639,16 +2576,13 @@ }, { "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": true - }, + "execution_count": 14, + "metadata": {}, "outputs": [], "source": [ - "xvals = np.linspace(-4, 5, 50) + np.cos(2/9*np.pi*xvals+np.pi/4)\n", + "xvals = np.linspace(-4, 5, 50)\n", "tvals = np.linspace(-500, 1500, 25)\n", "\n", - "\n", "for xv in xvals:\n", " for tv in tvals:\n", " # just some arbitrary semi good looking function\n", @@ -2660,7 +2594,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -2745,7 +2679,7 @@ " };\n", "\n", " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", + " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", @@ -3240,7 +3174,7 @@ " // Register the callback with on_msg.\n", " comm.on_msg(function(msg) {\n", " //console.log('receiving', msg['content']['data'], msg);\n", - " // Pass the mpl event to the overriden (by mpl) onmessage function.\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", " ws.onmessage(msg['content']['data'])\n", " });\n", " return ws;\n", @@ -3392,9 +3326,12 @@ " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", @@ -3443,7 +3380,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -3461,21 +3398,19 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Interrupted 2D scans (a hole in the cheese)\n", + "## Warped 2D rectangular sweep scan\n", "\n", - "In case a sweep in interrupted, the entire grid will not be filled out. This is also supported,\n", - "in fact, any single rectangular hole is allowed" + "A nice feature of the new dataset is that the grid may be warped; it makes no difference.\n", + "Here we warp the x axis of the previous scan to increase the resolution in the right half plane." ] }, { "cell_type": "code", - "execution_count": 21, - "metadata": { - "collapsed": true - }, + "execution_count": 16, + "metadata": {}, "outputs": [], "source": [ - "data_set = new_data_set('warped-with-hole-2D-scan')\n", + "data_set = new_data_set('warped-2D-scan')\n", "data_set.add_parameter(x)\n", "data_set.add_parameter(t)\n", "data_set.add_parameter(z)" @@ -3483,44 +3418,885 @@ }, { "cell_type": "code", - "execution_count": 22, - "metadata": { - "collapsed": true - }, + "execution_count": 17, + "metadata": {}, "outputs": [], "source": [ "xvals = np.linspace(-4, 5, 50) + np.cos(2/9*np.pi*xvals+np.pi/4)\n", "tvals = np.linspace(-500, 1500, 25)\n", "\n", "\n", - "# define two small forbidden range functions\n", - "def no_x(xv):\n", - " if xv > 0 and xv < 3:\n", - " return True\n", - " else:\n", - " return False\n", - " \n", - "def no_t(tv):\n", - " if tv > 0 and tv < 450:\n", - " return True\n", - " else:\n", - " return False\n", - "\n", "for xv in xvals:\n", " for tv in tvals:\n", - " if no_x(xv) and no_t(tv):\n", - " continue\n", - " else:\n", - " # just some arbitrary semi good looking function\n", - " zv = np.sin(2*np.pi*xv)*np.cos(2*np.pi*0.001*tv) + 0.001*tv\n", - " data_set.add_result({'x': xv, 't': tv, 'z': zv})\n", + " # just some arbitrary semi good looking function\n", + " zv = np.sin(2*np.pi*xv)*np.cos(2*np.pi*0.001*tv) + 0.001*tv\n", + " data_set.add_result({'x': xv, 't': tv, 'z': zv})\n", "\n", "data_set.mark_complete()" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " if (mpl.ratio != 1) {\n", + " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", + " }\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " fig.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var backingStore = this.context.backingStorePixelRatio ||\n", + "\tthis.context.webkitBackingStorePixelRatio ||\n", + "\tthis.context.mozBackingStorePixelRatio ||\n", + "\tthis.context.msBackingStorePixelRatio ||\n", + "\tthis.context.oBackingStorePixelRatio ||\n", + "\tthis.context.backingStorePixelRatio || 1;\n", + "\n", + " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width * mpl.ratio);\n", + " canvas.attr('height', height * mpl.ratio);\n", + " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('