"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"##Simple Example\n",
"Here is a simple first example. First we'll import the `bokeh.plotting`\n",
"module, which defines the graphical functions and primitives."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from bokeh.plotting import *\n",
"output_notebook()\n",
"import numpy as np"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"\n",
" \n",
" \n",
" Bokeh Plot\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Configuring embedded BokehJS mode.
\n",
" \n",
""
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = np.linspace(-6, 6, 100)\n",
"y = np.cos(x)\n",
"circle(x, y, color=\"red\", plot_width=500, plot_height=500)\n",
"show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"\n",
" \n",
" \n",
" Bokeh Plot\n",
" \n",
" \n",
" \n",
" Plots
\n",
" \n",
""
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Bar Plot Example\n",
"\n",
"Bokeh's core display model relies on *composing graphical primitives* which\n",
"are bound to data series. This is similar in spirit to Protovis and D3,\n",
"and different than most other Python plotting libraries (except for perhaps\n",
"Vincent and other, newer libraries)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from bokeh.sampledata.autompg import autompg\n",
"grouped = autompg.groupby(\"yr\")\n",
"mpg = grouped[\"mpg\"]\n",
"avg = mpg.mean()\n",
"std = mpg.std()\n",
"years = np.asarray(grouped.groups.keys())\n",
"american = autompg[autompg[\"origin\"]==1]\n",
"japanese = autompg[autompg[\"origin\"]==3]"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For each year, we want to plot the distribution of MPG within that year."
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"hold(True)\n",
"figure()\n",
"quad(left=years-0.4, right=years+0.4, bottom=avg-std, top=avg+std, \n",
" fill_alpha=0.4)\n",
"circle(x=np.asarray(japanese[\"yr\"]), y=np.asarray(japanese[\"mpg\"]), \n",
" size=8,\n",
" alpha=0.4, line_color=\"red\", fill_color=None, line_width=2)\n",
"triangle(x=np.asarray(american[\"yr\"]), y=np.asarray(american[\"mpg\"]),\n",
" size=8, alpha=0.4, line_color=\"blue\", fill_color=None,\n",
" line_width=2)\n",
"hold(False)\n",
"show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"\n",
" \n",
" \n",
" Bokeh Plot\n",
" \n",
" \n",
" \n",
" Plots
\n",
" \n",
""
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"This kind of approach can be used to generate other kinds of interesting plots, like some of the following which are available on the [Bokeh web page](http://bokeh.pydata.org). \n",
"\n",
"*(Click on any of the thumbnails to open the interactive version.)*\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"More Information\n",
"----------------\n",
"\n",
"There's a nice, comprehensive tutorial with exercises at: [http://bokeh.pydata.org/tutorial/index.html](http://bokeh.pydata.org/tutorial/index.html)\n",
"\n",
"For the full documentation & live examples: [http://bokeh.pydata.org](http://bokeh.pydata.org)\n",
"\n",
"GitHub: [https://github.com/ContinuumIO/bokeh](https://github.com/ContinuumIO/bokeh)\n",
"\n",
""
]
}
],
"metadata": {}
}
]
}