#!/usr/bin/env python
# coding: utf-8
#
#
# # Bokeh 5-minute Overview
#
# Bokeh is an interactive web visualization library for Python
# (and other languages). It provides d3-like novel graphics, over
# large datasets, all without requiring any knowledge of Javascript. It
# has a Matplotlib compatibility layer, and it works great with
# the IPython Notebook, but can also be used to generate standalone HTML.
#
# ## Simple Example
#
# Here is a simple first example. First we'll import the `bokeh.plotting`
# module, which defines the graphical functions and primitives.
# In[1]:
from bokeh.plotting import figure, output_notebook, show
# 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.)
# In[2]:
output_notebook()
# Next, we'll import NumPy and create some simple data.
# In[3]:
from numpy import cos, linspace
x = linspace(-6, 6, 100)
y = cos(x)
# Now we'll call Bokeh's `circle()` function to render a red circle at
# each of the points in x and y.
#
# We can immediately interact with the plot:
#
# * click-drag will pan the plot around.
# * mousewheel will zoom in and out
#
# (The toolbar is simply a default one that is available for all plots;
# this can be configured dynamically via the `tools` keyword argument.)
# In[4]:
p = figure(width=500, height=500)
p.circle(x, y, size=7, color="firebrick", alpha=0.5)
show(p)
# # Bar Plot Example
#
#
# Bokeh's core display model relies on *composing graphical primitives* which
# are bound to data series. This is similar in spirit to Protovis and D3,
# and different than most other Python plotting libraries (except for perhaps
# Vincent and other, newer libraries).
#
# A slightly more sophisticated example demonstrates this idea.
#
# Bokeh ships with a small set of interesting "sample data" in the `bokeh.sampledata`
# package. We'll load up some historical automobile mileage data, which is returned
# as a Pandas `DataFrame`.
# In[5]:
from bokeh.sampledata.autompg import autompg
from numpy import array
grouped = autompg.groupby("yr")
mpg = grouped["mpg"]
avg = mpg.mean()
std = mpg.std()
years = array(list(grouped.groups.keys()))
american = autompg[autompg["origin"]==1]
japanese = autompg[autompg["origin"]==3]
# For each year, we want to plot the distribution of MPG within that year.
# In[6]:
p = figure()
p.quad(left=years-0.4, right=years+0.4, bottom=avg-std, top=avg+std, fill_alpha=0.4)
p.circle(x=japanese["yr"], y=japanese["mpg"], size=8,
alpha=0.4, line_color="red", fill_color=None, line_width=2)
p.triangle(x=american["yr"], y=american["mpg"], size=8,
alpha=0.4, line_color="blue", fill_color=None, line_width=2)
show(p)
# # 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/en/latest).
#
# *(Click on any of the thumbnails to open the interactive version.)*
#
#
![]() |
# ![]() |
# ![]() |
#
![]() |
# ![]() |
# ![]() |
#