Skip to content

Instantly share code, notes, and snippets.

@yanivmo
Last active April 18, 2017 14:40
Show Gist options
  • Save yanivmo/205473dea8b9da43cf2a0cfeab62b29d to your computer and use it in GitHub Desktop.
Save yanivmo/205473dea8b9da43cf2a0cfeab62b29d to your computer and use it in GitHub Desktop.
Example of a box-and-whiskers diagram with a global average span, using Bokeh.BoxPlot and Pandas.DataFrame.
import bokeh.charts as bch
import pandas as pn
from bokeh.models import CrosshairTool, PanTool, ResetTool, WheelZoomTool, Span
# Input data as a list of tuples
data = [
(1, -3),
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(1, 10),
(2, 2),
(2, 3),
(2, 4),
(3, 0),
(3, 2),
(3, 4),
]
# Convert the data to DataFrame and name the columns
frames = pn.DataFrame(data, columns=['sha256', 'duration'])
# Configure the tools
wheel_zoom = WheelZoomTool()
tools = [PanTool(), wheel_zoom, ResetTool(), CrosshairTool(dimensions='width')]
# Label argument controlls the x axis; the data will be grouped by this field.
# Values argument controlles the y axis.
plot = bch.BoxPlot(frames, label='sha256', values='duration', tools=tools, legend=False, color='sha256')
# Make the wheel tool active by default
plot.toolbar.active_scroll = wheel_zoom
# Draw a horizontal line for the global average
global_average = Span(location=frames['duration'].mean(),
dimension='width',
line_color='red',
line_dash='dashed',
line_width=2)
plot.add_layout(global_average)
bch.output_file('candlestick.html')
bch.show(plot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment