{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "from bokeh.plotting import *\n", "import pandas as pd\n", "N = 80\n", "output_notebook()" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "

Configuring embedded BokehJS mode.

\n", " \n", "
" ], "metadata": {}, "output_type": "display_data" } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "from bokeh import plotting\n", "colors = [\n", " \"#1f77b4\",\n", " \"#ff7f0e\", \n", " \"#2ca02c\", \"#98df8a\",\n", " \"#d62728\", \"#ff9896\",\n", " \"#9467bd\", \"#c5b0d5\",\n", " \"#8c564b\", \"#c49c94\",\n", " \"#e377c2\", \"#f7b6d2\",\n", " \"#7f7f7f\", \"#ffbb78\",\n", " \"#bcbd22\", \"#dbdb8d\",\n", " \"#17becf\", \"#9edae5\"\n", " ]\n", "def make_color_cycle():\n", " ic = iter(colors)\n", " while True:\n", " try:\n", " yield ic.next()\n", " except StopIteration as e:\n", " ic = iter(colors)\n", "\n", "\n", "def multiplot(df, colsets, **kwargs):\n", " x_range = [None]\n", "\n", " x=df.index\n", " columns = dict([[c, df[c]] for c in df.columns])\n", " columns['x'] = df.index\n", " datasource = plotting.ColumnDataSource(columns)\n", " def default_plot(c__, title=False):\n", " defaults = dict(f=plotting.line)\n", " defaults.update(kwargs)\n", " if type(c__) == type({}):\n", " defaults.update(c__)\n", " colname = defaults.pop('col')\n", " else:\n", " colname = c__\n", " plotf = defaults.pop('f')\n", " l = plotf('x', colname, source=datasource,\n", " x_range=x_range[0], color=color_cycle.next(), \n", " legend=colname, title=title or colname, **defaults)\n", " x_range[0] = l.x_range\n", " return l\n", " rows = []\n", "\n", " color_cycle = make_color_cycle()\n", " for col_or_colset in colsets:\n", " if type(col_or_colset) == type([]):\n", " plotting.hold(True)\n", " l = default_plot(col_or_colset[0])\n", " for c in col_or_colset[1:]:\n", " default_plot(c)\n", " plotting.hold(False)\n", " else:\n", " l = default_plot(col_or_colset)\n", "\n", " rows.append([l])\n", " plotting.figure()\n", " plotting.gridplot(rows)\n", " plotting.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "x = np.linspace(0, 4*np.pi, N)\n", "\n", "df = pd.DataFrame( index=x)\n", "df['y'] = np.sin(x)\n", "df['z'] = np.sin(2*x) + 1.75 * np.cos(x)\n", "df['y2'] = np.sin(1.7*x)\n", "df['w'] = np.tan(x)\n", "multiplot(df, [dict(col='z', f=plotting.scatter), ['y', 'z'], 'w'], plot_width=900, plot_height=200, \n", " f=plotting.scatter, tools=\"save, select, zoom, resize, crosshair\")" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " \n", " \n", " \n", " \n", "
Plots
\n", "\n", " \n", "
" ], "metadata": {}, "output_type": "display_data" } ], "prompt_number": 15 }, { "cell_type": "code", "collapsed": false, "input": [ "multiplot(df, ['z', ['y', 'z'], 'w'], plot_width=900, plot_height=200, tools=\"save, zoom, resize, crosshair\")" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " \n", " \n", " \n", " \n", "
Plots
\n", "\n", " \n", "
" ], "metadata": {}, "output_type": "display_data" } ], "prompt_number": 16 }, { "cell_type": "code", "collapsed": false, "input": [ "multiplot(df, ['y','y2'], plot_width=700, plot_height=200, tools=\"pan,zoom,preview,resize,crosshair\")" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " \n", " \n", " \n", " \n", "
Plots
\n", "\n", " \n", "
" ], "metadata": {}, "output_type": "display_data" } ], "prompt_number": 17 }, { "cell_type": "code", "collapsed": false, "input": [ "#this plot causes an error, I'm not sure why. Running it completely borks js on the page\n", "multiplot(df, [['y','y2']], plot_width=700, plot_height=200, tools=\"pan,zoom,preview,resize,crosshair\")" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }