{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating Interactive Visualizations with Bokeh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Bokeh](http://bokeh.pydata.org) is a Python package for creating interactive, browser-based visualizations, and is well-suited for \"big data\" applications.\n", "\n", "* Bindings can (and have) been created for other languages.\n", "\n", "\n", "\n", "Bokeh allows users to create interactive html visualizations without using JS.\n", "\n", "Bokeh is a **language-based** visualization system. This allows for:\n", "\n", "* high-level commands for data binding, transformation, interaction\n", "* low-level power to deeply customize\n", "\n", "Bokeh philosophy: \n", "\n", "> Make a smart choice when it is possible to do so automatically, and expose low-level capabilities when it is not." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# How does Bokeh work?\n", "\n", "Bokeh writes to a custom-built HTML5 Canvas library, which affords it high performance. This allows it to integrate with other web tools, such as Google Maps.\n", "\n", "Bokeh plots are based on visual elements called **glyphs** that are bound to data objects." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Installation\n", "\n", "Bokeh can be installed easily either via `pip` or `conda` (if using Anaconda):\n", "\n", " pip install bokeh\n", " \n", " conda install bokeh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A Simple Example\n", "\n", "First we'll import the bokeh.plotting module, which defines the graphical functions and primitives." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import bokeh.plotting as bk" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we'll tell Bokeh to display its plots directly into the notebook. This will cause all of the Javascript and data to be embedded directly into the HTML of the notebook itself. (Bokeh can output straight to HTML files, or use a server, which we'll look at later.)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(global) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " var force = true;\n", "\n", " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n", " window._bokeh_onload_callbacks = [];\n", " window._bokeh_is_loading = undefined;\n", " }\n", "\n", "\n", " \n", " if (typeof (window._bokeh_timeout) === \"undefined\" || force === true) {\n", " window._bokeh_timeout = Date.now() + 5000;\n", " window._bokeh_failed_load = false;\n", " }\n", "\n", " var NB_LOAD_WARNING = {'data': {'text/html':\n", " \"\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"\n", " | mpg | \n", "cyl | \n", "displ | \n", "hp | \n", "weight | \n", "accel | \n", "yr | \n", "origin | \n", "name | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "18.0 | \n", "8 | \n", "307.0 | \n", "130 | \n", "3504 | \n", "12.0 | \n", "70 | \n", "1 | \n", "chevrolet chevelle malibu | \n", "
1 | \n", "15.0 | \n", "8 | \n", "350.0 | \n", "165 | \n", "3693 | \n", "11.5 | \n", "70 | \n", "1 | \n", "buick skylark 320 | \n", "
2 | \n", "18.0 | \n", "8 | \n", "318.0 | \n", "150 | \n", "3436 | \n", "11.0 | \n", "70 | \n", "1 | \n", "plymouth satellite | \n", "
3 | \n", "16.0 | \n", "8 | \n", "304.0 | \n", "150 | \n", "3433 | \n", "12.0 | \n", "70 | \n", "1 | \n", "amc rebel sst | \n", "
4 | \n", "17.0 | \n", "8 | \n", "302.0 | \n", "140 | \n", "3449 | \n", "10.5 | \n", "70 | \n", "1 | \n", "ford torino | \n", "
5 | \n", "15.0 | \n", "8 | \n", "429.0 | \n", "198 | \n", "4341 | \n", "10.0 | \n", "70 | \n", "1 | \n", "ford galaxie 500 | \n", "
6 | \n", "14.0 | \n", "8 | \n", "454.0 | \n", "220 | \n", "4354 | \n", "9.0 | \n", "70 | \n", "1 | \n", "chevrolet impala | \n", "
7 | \n", "14.0 | \n", "8 | \n", "440.0 | \n", "215 | \n", "4312 | \n", "8.5 | \n", "70 | \n", "1 | \n", "plymouth fury iii | \n", "
8 | \n", "14.0 | \n", "8 | \n", "455.0 | \n", "225 | \n", "4425 | \n", "10.0 | \n", "70 | \n", "1 | \n", "pontiac catalina | \n", "
9 | \n", "15.0 | \n", "8 | \n", "390.0 | \n", "190 | \n", "3850 | \n", "8.5 | \n", "70 | \n", "1 | \n", "amc ambassador dpl | \n", "