{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "from ipywidgets import StaticInteract, RangeWidget, RadioWidget\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "# here we define the function which depends on variables.\n", "# one can define functions with as many variables as desired\n", "\n", "def f(x,var):\n", " return np.sinc(x/var)**2\n", "\n", "# this is the routine which calls the function f(x,var)\n", "# and plots the variation with respect to var\n", "\n", "def plot(var):\n", " fig, ax = plt.subplots(figsize=(4, 3),\n", " subplot_kw={'axisbg':'#EEEEEE',\n", " 'axisbelow':True})\n", " ax.grid(color='w', linewidth=2, linestyle='solid')\n", " x = np.linspace(-50, 50, 1001)\n", " ax.plot(x, f(x,var), lw=5, alpha=0.4, label=var)\n", " ax.set_xlim(-50, 50)\n", " ax.set_ylim(-0.1, 1.1)\n", " ax.legend(loc='upper right')\n", " return fig\n", "\n", "# here we look at the function's dependence on the value of var.\n", "# we can add any number of variables var1, var2 in the same way.\n", "# the syntax in the RangeWidget is (start, end, increment)\n", "\n", "StaticInteract(plot,var=RangeWidget(10, 100, 10))" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", " \n", " \n", "