{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "#%matplotlib inline\n", "from ipywidgets import interact, interactive, fixed, interact_manual\n", "import ipywidgets as widgets\n", "\n", "from matplotlib.animation import FuncAnimation\n", "from IPython.display import HTML\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5447d50f9dfe4d9f82f766e11b682e23", "version_major": 2, "version_minor": 0 }, "text/plain": [ "A Jupyter Widget" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ ">" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def wave_anim(k, c):\n", " x = np.linspace(-5, 5, 1000)\n", " fig, ax = plt.subplots()\n", " im, = ax.plot(x, np.sin(x))\n", " update = lambda t: im.set_data(x, np.sin(k*x-c*k*t))\n", " anim = FuncAnimation(fig, update, interval=100, frames=int(2*np.pi/(c*k)))\n", " return anim\n", "\n", "display = lambda k, c: HTML(wave_anim(k, c).to_jshtml())\n", "interact(display, k=(0.1, 5, 0.1), c=(0.01, 0.5, 0.01))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.3" } }, "nbformat": 4, "nbformat_minor": 2 }