{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from bokeh.sampledata.autompg import autompg as df\n", "from bokeh.sampledata.olympics2014 import data\n", "from bokeh.sampledata.iris import flowers\n", "\n", "from bokeh.charts import Scatter, output_notebook, show\n", "from bokeh.charts.operations import blend\n", "from bokeh.charts.utils import df_from_json\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "output_notebook()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scatter0 = Scatter(\n", " df, x='mpg', title=\"x='mpg'\", xlabel=\"Miles Per Gallon\")\n", "show(scatter0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scatter1 = Scatter(\n", " df, x='mpg', y='hp', title=\"x='mpg', y='hp'\",\n", " xlabel=\"Miles Per Gallon\", ylabel=\"Horsepower\", legend='top_right')\n", "show(scatter1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scatter2 = Scatter(\n", " df, x='mpg', y='hp', color='cyl', title=\"x='mpg', y='hp', color='cyl'\",\n", " xlabel=\"Miles Per Gallon\", ylabel=\"Horsepower\", legend='top_right')\n", "show(scatter2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scatter3 = Scatter(\n", " df, x='mpg', y='hp', color='origin', title=\"x='mpg', y='hp', color='origin'\",\n", " xlabel=\"Miles Per Gallon\", ylabel=\"Horsepower\", legend='top_right')\n", "show(scatter3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scatter4 = Scatter(\n", " df, x='mpg', y='hp', color='cyl', marker='origin', title=\"x='mpg', y='hp', color='cyl', marker='origin'\",\n", " xlabel=\"Miles Per Gallon\", ylabel=\"Horsepower\", legend='top_right')\n", "show(scatter4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example with nested json/dict like data, which has been pre-aggregated and pivoted" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "df2 = df_from_json(data)\n", "df2 = df2.sort('total', ascending=False)\n", "df2 = df2.head(10)\n", "df2 = pd.melt(df2, id_vars=['abbr', 'name'])\n", "\n", "scatter5 = Scatter(\n", " df2, x='value', y='name', color='variable', title=\"x='value', y='name', color='variable'\",\n", " xlabel=\"Medals\", ylabel=\"Top 10 Countries\", legend='bottom_right')\n", "show(scatter5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use blend operator to \"stack\" variables" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scatter6 = Scatter(flowers, x=blend('petal_length', 'sepal_length', name='length'),\n", " y=blend('petal_width', 'sepal_width', name='width'), color='species',\n", " title='x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',\n", " legend='top_right')\n", "show(scatter6)" ] } ], "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.4" } }, "nbformat": 4, "nbformat_minor": 0 }