In [1]:
from math import pi
import pandas as pd
In [2]:
from bokeh.sampledata.stocks import MSFT
from bokeh.plotting import figure, output_notebook, show
In [3]:
output_notebook()
Loading BokehJS ...
In [4]:
df = pd.DataFrame(MSFT)[:50]
df['date'] = pd.to_datetime(df['date'])

mids = (df.open + df.close)/2
spans = abs(df.close-df.open)

inc = df.close > df.open
dec = df.open > df.close
w = 12*60*60*1000 # half day in ms
In [5]:
p = figure(x_axis_type="datetime", plot_width=800, plot_height=500, title = "MSFT Candlestick")
p.xaxis.major_label_orientation = pi/4
p.grid.grid_line_alpha=0.3
In [6]:
p.segment(df.date, df.high, df.date, df.low, color='black')
p.rect(df.date[inc], mids[inc], w, spans[inc], fill_color="#D5E1DD", line_color="black")
p.rect(df.date[dec], mids[dec], w, spans[dec], fill_color="#F2583E", line_color="black")
Out[6]:
<bokeh.models.renderers.GlyphRenderer at 0x10dd3f1d0>
In [7]:
show(p)
Out[7]:

<Bokeh Notebook handle for In[7]>