{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import pi, arange, sin, cos\n",
      "import numpy as np\n",
      "import os.path"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from bokeh.objects import (\n",
      "    Plot, DataRange1d, LinearAxis, Grid, ColumnDataSource, Glyph, \n",
      "    ObjectArrayDataSource, PanTool, ZoomTool\n",
      ")\n",
      "from bokeh.glyphs import Circle\n",
      "from bokeh import session"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = arange(-2*pi, 2*pi, 0.1)\n",
      "y = sin(x)\n",
      "width = np.ones_like(x) * 0.02\n",
      "height = np.ones_like(x) * 0.2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "source = ColumnDataSource(data=dict(x=x, y=y,width=width, height=height))\n",
      "xdr = DataRange1d(sources=[source.columns(\"x\")])\n",
      "ydr = DataRange1d(sources=[source.columns(\"y\")])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "circle = Circle(x=\"x\", y=\"y\", fill_color=\"red\", radius=5, line_color=\"black\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "glyph_renderer = Glyph(\n",
      "    data_source = source,\n",
      "    xdata_range = xdr,\n",
      "    ydata_range = ydr,\n",
      "    glyph = circle,\n",
      ")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pantool = PanTool(dataranges=[xdr, ydr], dimensions=(\"width\",\"height\"))\n",
      "zoomtool = ZoomTool(dataranges=[xdr, ydr], dimensions=(\"width\",\"height\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "xaxis = LinearAxis(plot=plot, dimension=0)\n",
      "yaxis = LinearAxis(plot=plot, dimension=1)\n",
      "xgrid = Grid(plot=plot, dimension=0) \n",
      "ygrid = Grid(plot=plot, dimension=1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plot.renderers.append(glyph_renderer)\n",
      "plot.tools = [pantool,zoomtool]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sess = session.NotebookSession()\n",
      "sess.add(\n",
      "    source, xdr, ydr, xaxis, yaxis, xgrid, ygrid, pantool, zoomtool, plot, glyph_renderer\n",
      ")\n",
      "sess.plotcontext.children.append(plot)\n",
      "sess.plotcontext._dirty = True"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sess.notebooksources()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sess.show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}