import pandas as pd
from bokeh.sampledata.glucose import data
from bokeh.plotting import figure, output_notebook, show
p1 = figure(x_axis_type="datetime", plot_width=800)
summer = data['2010-7-01':'2010-09-30']
p1.line(summer.index, summer['glucose'], color='red', legend='glucose')
p1.line(summer.index, summer['isig'], color='blue', legend='isig')
p1.title.text = "Glucose Measurements"
show(p1)
<Bokeh Notebook handle for In[4]>
day = data.ix['2010-10-06']
highs = day[day['glucose'] > 180]
lows = day[day['glucose'] < 80]
p2 = figure(x_axis_type="datetime")
p2.title.text = "Glucose Range"
p2.xgrid.grid_line_color=None
p2.ygrid.grid_line_alpha=0.5
p2.line(day.index, day['glucose'], line_color="gray", line_dash="4 4", line_width=1, legend="glucose")
p2.scatter(highs.index, highs['glucose'], size=6, color='tomato', legend="high")
p2.scatter(lows.index, lows['glucose'], size=6, color='navy', legend="low")
show(p2)
<Bokeh Notebook handle for In[5]>
data['inrange'] = (data['glucose'] < 180) & (data['glucose'] > 80)
window = 30.5*288 #288 is average number of samples in a month
inrange = pd.rolling_sum(data.inrange, int(window))
inrange = inrange.dropna()
inrange = inrange/float(window)
p3 = figure(x_axis_type="datetime")
p3.title.text = "Glucose In-Range Rolling Sum"
p3.line(inrange.index, inrange, line_color="navy")
show(p3)
/Users/bryan/anaconda/envs/bk012/lib/python3.5/site-packages/ipykernel/__main__.py:3: FutureWarning: pd.rolling_sum is deprecated for Series and will be removed in a future version, replace with Series.rolling(center=False,window=8784).sum() app.launch_new_instance()
<Bokeh Notebook handle for In[6]>