From 919674870c5a312391ef134c533e8870cd5031ed Mon Sep 17 00:00:00 2001 From: Marci Date: Wed, 25 Nov 2015 13:46:29 -0800 Subject: [PATCH] gui 1 --- .../1 - Interact-checkpoint.ipynb | 136 ++++++++++-------- GUI/1 - Interact.ipynb | 136 ++++++++++-------- 2 files changed, 156 insertions(+), 116 deletions(-) diff --git a/GUI/.ipynb_checkpoints/1 - Interact-checkpoint.ipynb b/GUI/.ipynb_checkpoints/1 - Interact-checkpoint.ipynb index a2d1a77..9ecc48d 100644 --- a/GUI/.ipynb_checkpoints/1 - Interact-checkpoint.ipynb +++ b/GUI/.ipynb_checkpoints/1 - Interact-checkpoint.ipynb @@ -18,12 +18,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "# Start with some imports!\n", + "\n", "from __future__ import print_function\n", "from ipywidgets import interact, interactive, fixed\n", "import ipywidgets as widgets" @@ -55,12 +57,13 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "# Very basic function\n", "def f(x):\n", " return x" ] @@ -69,12 +72,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "When you pass this function as the first argument to `interact` along with an integer keyword argument (`x=10`), a slider is generated and bound to the function parameter." + "When you pass this function as the first argument to `interact` along with an integer keyword argument (`x=10`), a slider is generated and bound to the function parameter. Note that the semicolon here just prevents an **out** cell from showing up." ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 33, "metadata": { "collapsed": false }, @@ -82,7 +85,7 @@ { "data": { "text/plain": [ - "-2" + "-8" ] }, "metadata": {}, @@ -90,7 +93,8 @@ } ], "source": [ - "interact(f, x=10);" + "# Generate a slider to interact with\n", + "interact(f, x=10,);" ] }, { @@ -104,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 34, "metadata": { "collapsed": false }, @@ -112,7 +116,7 @@ { "data": { "text/plain": [ - "True" + "False" ] }, "metadata": {}, @@ -120,6 +124,7 @@ } ], "source": [ + "# Booleans generate checkboxes\n", "interact(f, x=True);" ] }, @@ -132,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 39, "metadata": { "collapsed": false }, @@ -140,7 +145,7 @@ { "data": { "text/plain": [ - "u'Hello!!!'" + "u'string'" ] }, "metadata": {}, @@ -148,6 +153,7 @@ } ], "source": [ + "# Strings generate text areas\n", "interact(f, x='Hi there!');" ] }, @@ -160,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 40, "metadata": { "collapsed": false }, @@ -168,7 +174,7 @@ { "data": { "text/plain": [ - "(True, 0.3)" + "(True, 1.1)" ] }, "metadata": {}, @@ -176,6 +182,7 @@ } ], "source": [ + "# Using a decorator!\n", "@interact(x=True, y=1.0)\n", "def g(x, y):\n", " return (x, y)" @@ -197,12 +204,13 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 42, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "# Again, a simple function\n", "def h(p, q):\n", " return (p, q)" ] @@ -216,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 43, "metadata": { "collapsed": false }, @@ -224,7 +232,7 @@ { "data": { "text/plain": [ - "(0, 20)" + "(13, 20)" ] }, "metadata": {}, @@ -264,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 44, "metadata": { "collapsed": false }, @@ -272,7 +280,7 @@ { "data": { "text/plain": [ - "20" + "10" ] }, "metadata": {}, @@ -280,6 +288,7 @@ } ], "source": [ + "# Can call the IntSlider to get more specific\n", "interact(f, x=widgets.IntSlider(min=-10,max=30,step=1,value=10));" ] }, @@ -315,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 49, "metadata": { "collapsed": false }, @@ -331,6 +340,7 @@ } ], "source": [ + "# Min,Max slider with Tuples\n", "interact(f, x=(0,4));" ] }, @@ -343,7 +353,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 50, "metadata": { "collapsed": false }, @@ -359,6 +369,7 @@ } ], "source": [ + "# (min, max, step)\n", "interact(f, x=(0,8,2));" ] }, @@ -371,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 51, "metadata": { "collapsed": false }, @@ -379,7 +390,7 @@ { "data": { "text/plain": [ - "10.0" + "5.0" ] }, "metadata": {}, @@ -399,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 52, "metadata": { "collapsed": false }, @@ -407,7 +418,7 @@ { "data": { "text/plain": [ - "4.98" + "4.99" ] }, "metadata": {}, @@ -427,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 53, "metadata": { "collapsed": false }, @@ -435,7 +446,7 @@ { "data": { "text/plain": [ - "5.0" + "5.5" ] }, "metadata": {}, @@ -457,7 +468,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 55, "metadata": { "collapsed": false }, @@ -485,7 +496,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 56, "metadata": { "collapsed": false }, @@ -517,25 +528,18 @@ "source": [ "If you are using Python 3, you can also specify widget abbreviations using [function annotations](https://docs.python.org/3/tutorial/controlflow.html#function-annotations).\n", "\n", + "\n", + "### PYTHON 3\n", "Define a function with a checkbox widget abbreviation for the argument `x`." ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 1)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m def f(x:True): # python 3 only\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" - ] - } - ], + "outputs": [], "source": [ "def f(x:True): # python 3 only\n", " return x" @@ -559,6 +563,13 @@ "interact(f);" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### PYTHON 2" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -568,7 +579,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 59, "metadata": { "collapsed": false }, @@ -579,7 +590,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 60, "metadata": { "collapsed": false }, @@ -592,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 61, "metadata": { "collapsed": false }, @@ -600,7 +611,7 @@ { "data": { "text/plain": [ - "True" + "False" ] }, "metadata": {}, @@ -634,7 +645,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 65, "metadata": { "collapsed": false }, @@ -653,7 +664,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 66, "metadata": { "collapsed": false }, @@ -671,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 67, "metadata": { "collapsed": false }, @@ -682,7 +693,7 @@ "ipywidgets.widgets.widget_box.Box" ] }, - "execution_count": 26, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -700,7 +711,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 68, "metadata": { "collapsed": false }, @@ -708,11 +719,11 @@ { "data": { "text/plain": [ - "(,\n", - " )" + "(,\n", + " )" ] }, - "execution_count": 27, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -730,7 +741,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 69, "metadata": { "collapsed": false }, @@ -738,7 +749,7 @@ { "data": { "text/plain": [ - "65" + "30" ] }, "metadata": {}, @@ -761,7 +772,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 70, "metadata": { "collapsed": false }, @@ -769,10 +780,10 @@ { "data": { "text/plain": [ - "{'a': 16, 'b': 49}" + "{'a': 10, 'b': 20}" ] }, - "execution_count": 29, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -790,7 +801,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 71, "metadata": { "collapsed": false }, @@ -798,10 +809,10 @@ { "data": { "text/plain": [ - "65" + "30" ] }, - "execution_count": 30, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -809,6 +820,15 @@ "source": [ "w.result" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Conclusion\n", + "\n", + "You should now have a basic understanding of how to use Interact in Jupyter Notebooks!" + ] } ], "metadata": { diff --git a/GUI/1 - Interact.ipynb b/GUI/1 - Interact.ipynb index a2d1a77..9ecc48d 100644 --- a/GUI/1 - Interact.ipynb +++ b/GUI/1 - Interact.ipynb @@ -18,12 +18,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "# Start with some imports!\n", + "\n", "from __future__ import print_function\n", "from ipywidgets import interact, interactive, fixed\n", "import ipywidgets as widgets" @@ -55,12 +57,13 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "# Very basic function\n", "def f(x):\n", " return x" ] @@ -69,12 +72,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "When you pass this function as the first argument to `interact` along with an integer keyword argument (`x=10`), a slider is generated and bound to the function parameter." + "When you pass this function as the first argument to `interact` along with an integer keyword argument (`x=10`), a slider is generated and bound to the function parameter. Note that the semicolon here just prevents an **out** cell from showing up." ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 33, "metadata": { "collapsed": false }, @@ -82,7 +85,7 @@ { "data": { "text/plain": [ - "-2" + "-8" ] }, "metadata": {}, @@ -90,7 +93,8 @@ } ], "source": [ - "interact(f, x=10);" + "# Generate a slider to interact with\n", + "interact(f, x=10,);" ] }, { @@ -104,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 34, "metadata": { "collapsed": false }, @@ -112,7 +116,7 @@ { "data": { "text/plain": [ - "True" + "False" ] }, "metadata": {}, @@ -120,6 +124,7 @@ } ], "source": [ + "# Booleans generate checkboxes\n", "interact(f, x=True);" ] }, @@ -132,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 39, "metadata": { "collapsed": false }, @@ -140,7 +145,7 @@ { "data": { "text/plain": [ - "u'Hello!!!'" + "u'string'" ] }, "metadata": {}, @@ -148,6 +153,7 @@ } ], "source": [ + "# Strings generate text areas\n", "interact(f, x='Hi there!');" ] }, @@ -160,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 40, "metadata": { "collapsed": false }, @@ -168,7 +174,7 @@ { "data": { "text/plain": [ - "(True, 0.3)" + "(True, 1.1)" ] }, "metadata": {}, @@ -176,6 +182,7 @@ } ], "source": [ + "# Using a decorator!\n", "@interact(x=True, y=1.0)\n", "def g(x, y):\n", " return (x, y)" @@ -197,12 +204,13 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 42, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "# Again, a simple function\n", "def h(p, q):\n", " return (p, q)" ] @@ -216,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 43, "metadata": { "collapsed": false }, @@ -224,7 +232,7 @@ { "data": { "text/plain": [ - "(0, 20)" + "(13, 20)" ] }, "metadata": {}, @@ -264,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 44, "metadata": { "collapsed": false }, @@ -272,7 +280,7 @@ { "data": { "text/plain": [ - "20" + "10" ] }, "metadata": {}, @@ -280,6 +288,7 @@ } ], "source": [ + "# Can call the IntSlider to get more specific\n", "interact(f, x=widgets.IntSlider(min=-10,max=30,step=1,value=10));" ] }, @@ -315,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 49, "metadata": { "collapsed": false }, @@ -331,6 +340,7 @@ } ], "source": [ + "# Min,Max slider with Tuples\n", "interact(f, x=(0,4));" ] }, @@ -343,7 +353,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 50, "metadata": { "collapsed": false }, @@ -359,6 +369,7 @@ } ], "source": [ + "# (min, max, step)\n", "interact(f, x=(0,8,2));" ] }, @@ -371,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 51, "metadata": { "collapsed": false }, @@ -379,7 +390,7 @@ { "data": { "text/plain": [ - "10.0" + "5.0" ] }, "metadata": {}, @@ -399,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 52, "metadata": { "collapsed": false }, @@ -407,7 +418,7 @@ { "data": { "text/plain": [ - "4.98" + "4.99" ] }, "metadata": {}, @@ -427,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 53, "metadata": { "collapsed": false }, @@ -435,7 +446,7 @@ { "data": { "text/plain": [ - "5.0" + "5.5" ] }, "metadata": {}, @@ -457,7 +468,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 55, "metadata": { "collapsed": false }, @@ -485,7 +496,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 56, "metadata": { "collapsed": false }, @@ -517,25 +528,18 @@ "source": [ "If you are using Python 3, you can also specify widget abbreviations using [function annotations](https://docs.python.org/3/tutorial/controlflow.html#function-annotations).\n", "\n", + "\n", + "### PYTHON 3\n", "Define a function with a checkbox widget abbreviation for the argument `x`." ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 1)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m def f(x:True): # python 3 only\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" - ] - } - ], + "outputs": [], "source": [ "def f(x:True): # python 3 only\n", " return x" @@ -559,6 +563,13 @@ "interact(f);" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### PYTHON 2" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -568,7 +579,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 59, "metadata": { "collapsed": false }, @@ -579,7 +590,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 60, "metadata": { "collapsed": false }, @@ -592,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 61, "metadata": { "collapsed": false }, @@ -600,7 +611,7 @@ { "data": { "text/plain": [ - "True" + "False" ] }, "metadata": {}, @@ -634,7 +645,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 65, "metadata": { "collapsed": false }, @@ -653,7 +664,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 66, "metadata": { "collapsed": false }, @@ -671,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 67, "metadata": { "collapsed": false }, @@ -682,7 +693,7 @@ "ipywidgets.widgets.widget_box.Box" ] }, - "execution_count": 26, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -700,7 +711,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 68, "metadata": { "collapsed": false }, @@ -708,11 +719,11 @@ { "data": { "text/plain": [ - "(,\n", - " )" + "(,\n", + " )" ] }, - "execution_count": 27, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -730,7 +741,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 69, "metadata": { "collapsed": false }, @@ -738,7 +749,7 @@ { "data": { "text/plain": [ - "65" + "30" ] }, "metadata": {}, @@ -761,7 +772,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 70, "metadata": { "collapsed": false }, @@ -769,10 +780,10 @@ { "data": { "text/plain": [ - "{'a': 16, 'b': 49}" + "{'a': 10, 'b': 20}" ] }, - "execution_count": 29, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -790,7 +801,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 71, "metadata": { "collapsed": false }, @@ -798,10 +809,10 @@ { "data": { "text/plain": [ - "65" + "30" ] }, - "execution_count": 30, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -809,6 +820,15 @@ "source": [ "w.result" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Conclusion\n", + "\n", + "You should now have a basic understanding of how to use Interact in Jupyter Notebooks!" + ] } ], "metadata": {