{ "metadata": { "name": "Z Callbacks" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "*this markdown cell loads the flot jQuery plugin, used for plotting*\n", "" ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Interactive JavaScript plots with kernel callbacks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is an example of a plotting widget, entirely in javascript, \n", "which can make callbacks to the Kernel to update data.\n", "\n", "In this case, there is a user-defined function (`update_plot`) that\n", "generates the new data for the plot. The widget has sliders, which\n", "trigger calls to this function when they change. There is a javascript\n", "callback hooked up, which updates a plot area with the new data when it arrives." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You must run this one code cell to define the function before it is available to the widget,\n", "then the plot should appear when you move one of the sliders." ] }, { "cell_type": "code", "collapsed": true, "input": [ "import json\n", "from IPython.core.display import JSON, display\n", "from scipy.special import jn\n", "from numpy import linspace\n", "\n", "def update_plot(n, xmax=10, npoints=200):\n", " x = linspace(0, xmax, npoints)\n", " lines = []\n", " for i in range(1,n+1):\n", " lines.append(zip(x,jn(x,i)))\n", " display(JSON(json.dumps(lines)))" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Bessel Functions**\n", "\n", "
\n", "\n", "
\n", "\n", "
\n", "\n", "
\n", "\n", "\n" ] } ], "metadata": {} } ] }