{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pandas as pd\n", "from bokeh.charts import Line, show, output_notebook, defaults" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "output_notebook()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "defaults.width = 550\n", "defaults.height = 400\n", "defaults.legend = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup fake sampled data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# build a dataset where multiple columns measure the same thing\n", "data = dict(python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111],\n", " pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130],\n", " jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160],\n", " test=['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar']\n", " )\n", "df = pd.DataFrame(data)\n", "\n", "# add a column with a range of dates, as if the values were sampled then\n", "df['date'] = pd.date_range('1/1/2015', periods=len(df.index), freq='D')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Build and show the charts" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# default behavior for dataframe input is to plot each numerical column as a line\n", "line = Line(df)\n", "show(line)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# build the line plots\n", "line0 = Line(df, y=['python', 'pypy', 'jython'],\n", " title=\"Interpreters (y=['python', 'pypy', 'jython'])\", ylabel='Duration', legend=True)\n", "show(line0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "line1 = Line(df, x='date', y=['python', 'pypy', 'jython'],\n", " title=\"Interpreters (x='date', y=['python', 'pypy', 'jython'])\", ylabel='Duration')\n", "show(line1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "line2 = Line(df, x='date', y=['python', 'pypy', 'jython'],\n", " dash=['python', 'pypy', 'jython'],\n", " title=\"Interpreters (x='date', y, dash=['python', 'pypy', 'jython'])\", ylabel='Duration')\n", "show(line2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "line3 = Line(df, x='date', y=['python', 'pypy', 'jython'],\n", " dash=['python', 'pypy', 'jython'],\n", " color=['python', 'pypy', 'jython'],\n", " title=\"Interpreters (x='date', y, dash, color=['python', 'pypy', 'jython'])\", ylabel='Duration')\n", "show(line3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "line4 = Line(df, x='date', y=['python', 'pypy', 'jython'],\n", " dash='test',\n", " color=['python', 'pypy', 'jython'],\n", " title=\"Interpreters (x='date', y, color=['python', 'pypy', 'jython'], dash='test')\", ylabel='Duration')\n", "show(line4)" ] } ], "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.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }