{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from ipywidgets import interact, interactive, fixed\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Welcome!\n", "This notebook demos an interactive cell within a slideshow using RISE" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "# Let's define a function (this cell can be hidden from the slideshow if you like)\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from ipywidgets import interact\n", "\n", "def plot_graph(a=-0.1,b=0.8,c=-0.3):\n", " # some arbitrary function of a,b,c\n", " x = np.linspace(0,10,100)\n", " y = a*a*np.square(x) + (b+a)*np.sin(x) + (c-a)*np.cos(x) + c*x\n", " plt.plot(x,y)\n", " plt.ylim(-30,30)\n", " plt.show()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Executing a static function call\n", "Change the numbers in the function call, hit ctrl-enter and it will re-execute. Everything shifts down when you change a number and re-execute, then shifts back to the 'correct' position if you execute another time without changing anything." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "# Here's a static evaluation with default args\n", "plot_graph(1.2,0.121,2.5)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Interactive widgets\n", "Now you can wiggle the sliders and see the effect on the graph. Yay! But if you re-execute the cell with ctrl-enter, the position will be broken. If you go back a slide and re-launch this slide, the position is correct again." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "interact(plot_graph, a=(-2,2,0.2), b=(-2,3,0.1), c=(-2,2,0.1));" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Slideshow", "jupytext": { "cell_metadata_filter": "all", "notebook_metadata_filter": "all,-language_info,-toc,-jupytext.text_representation.jupytext_version" }, "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.7.4" }, "livereveal": { "autolaunch": true }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }