{ "metadata": { "name": "", "signature": "sha256:ae58bbcb864b2646e45651a817db8b0c50fe52236e7528e505e1741eb23a7dd5" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\u201cthe greatest value of a picture is when it forces us to notice what we never expected to see.\u201d - John Turkey \n", "\n", "Here is a good resource for making matplotlib plots prettier: http://nbviewer.ipython.org/gist/olgabot/5357268\n", "\n", "That said, the fact that you have to do so much work to get something done points to a problem. \n", "\n", "Bokeh aims to fix this by making a matplotlib style plotting for the internet: http://nbviewer.ipython.org/github/damianavila/bokeh_overview/blob/master/Bokeh%20Overview.ipynb \n", "\n", "It's worth knowing about this package and exploring it, but it doesn't seem ready for prime time yet. \n", "\n", "First let's see an unsurprising example. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "from bokeh.sampledata.iris import flowers\n", "from bokeh.plotting import *\n", "\n", "output_notebook()" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ " \n", " \n", " \n", "
\n", " \n", " BokehJS successfully loaded.\n", "
" ], "metadata": {}, "output_type": "display_data" } ], "prompt_number": 22 }, { "cell_type": "code", "collapsed": false, "input": [ "# List of SVG colors http://www.december.com/html/spec/colorsvg.html\n", "\n", "colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}\n", "\n", "flowers['color'] = flowers['species'].map(lambda x: colormap[x])\n", "\n", "#setting the name kwarg will give this scatter plot a user\n", "#friendly id, and the corresponding embed.js will have a nice name\n", "#too\n", "scatter(flowers[\"petal_length\"], flowers[\"petal_width\"],\n", " color=flowers[\"color\"], fill_alpha=0.2, size=10, name=\"iris\",\n", " tools=\"pan,wheel_zoom,box_zoom,reset,resize\")\n", "\n", "# http://bokeh.pydata.org/docs/glyphs_ref.html#circle - glyph documentation. \n", "\n", "show()" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "
\n", "\n" ], "metadata": {}, "output_type": "display_data" } ], "prompt_number": 29 }, { "cell_type": "code", "collapsed": false, "input": [ "show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 21 }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a building block for a larger project which shows the project trying to reach parity with d3, which is pretty sweet. \n", "\n", "Compare: http://bl.ocks.org/mbostock/4063663 with http://bokeh.pydata.org/docs/gallery/iris_splom.html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One other peice powering this is the linked_brushing" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from bokeh.plotting import scatter, output_notebook, show, gridplot\n", "from bokeh.objects import ColumnDataSource\n", "import numpy as np\n", "output_notebook()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "N=100\n", "x = np.linspace(0, 4*np.pi, N)\n", "y = np.sin(x)\n", "z = np.cos(x)\n", "source = ColumnDataSource()\n", "source.add(data=x, name='x')\n", "source.add(data=y, name='y')\n", "source.add(data=z, name='z')\n", "s1 = scatter('x', 'y', source=source, width=300, height=300)\n", "#note that s2 shares the same x data source, but has a different y\n", "s2 = scatter('x', 'z', source=source, width=300, height=300)\n", "gridplot([[s1,s2]])\n", "show()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, let's talk about animation because captures a lot of the powerful ideas which are promised by Bokeh and other visualization packages (because what is interaction but on demand animation)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This idea let's you make interactive \"apps\" in pure python. \n", "\n", "http://107.170.242.157:5010/stocks\n", "/glyphs/taylor_server.ipynb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All of these exampls are super sanitized though. Here I tried my hand at using the library directly: [Animating Baby Names](animating_baby_names.ipynb). Let's check it out!" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }