{
 "metadata": {
  "name": "",
  "signature": "sha256:b9cb57231bd39c8177a25a6014ee97b9891bd8778af613726662ecaf75b5d8df"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Basic Interactor Demo\n",
      "---------------------\n",
      "\n",
      "This demo shows off an interactive visualization using [Bokeh](http://bokeh.pydata.org) for plotting, and Ipython interactors for widgets. The demo runs entirely inside the Ipython notebook, with no Bokeh server required.\n",
      "\n",
      "The dropdown offers a choice of trig functions to plot, and the sliders control the frequency, amplitude, and phase. \n",
      "\n",
      "To run, click on, `Cell->Run All` in the top menu, then scroll to the bottom and move the sliders. "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from bokeh.objects import ColumnDataSource\n",
      "from bokeh.plotting import *\n",
      "\n",
      "import numpy as np"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = np.linspace(0, 2*np.pi, 2000)\n",
      "y = np.sin(x)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "output_notebook()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "source = ColumnDataSource(data=dict(x=x, y=y))\n",
      "\n",
      "p = figure(title=\"simple line example\", plot_height=300, plot_width=600)\n",
      "p.line(x, y, color=\"#2222aa\", line_with=3, source=source, name=\"foo\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def update(f, w=1, A=1, phi=0):\n",
      "    if   f == \"sin\": func = np.sin\n",
      "    elif f == \"cos\": func = np.cos\n",
      "    elif f == \"tan\": func = np.tan\n",
      "    source.data['y'] = A * func(w * x + phi)\n",
      "    source.push_notebook()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "show(p)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from IPython.html.widgets import interact\n",
      "interact(update, f=[\"sin\", \"cos\", \"tan\"], w=(0,100), A=(1,10), phi=(0, 10, 0.1))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}