Unfortunately Bokeh 0.4.4 broke nbviewer rendering capabilities, but this has been fixed on master and will be working again with the release of 0.5. In the meantime, it's worth double-checking to make sure you're on a working version.
import bokeh
bokeh.print_versions()
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Bokeh version: 0.4.4-267-ge9807af Python version: 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] Platform: Linux-3.11.0-031100rc7-generic-x86_64 (#201308252135 SMP Mon Aug 26 01:35:51 UTC 2013) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
from bokeh.plotting import *
from bokeh.objects import HoverTool
from collections import OrderedDict
#5 datasets (rows)
#8 buckets (columns)
buckets = ['AMOUNT', 'BUYER', 'TENDER TRACKING', 'TENDER FEATURES', 'AWARD TRACKING', 'AWARD FEATURES', 'SYSTEM', 'SUPPLIER']
datasets = ['Canada', 'Turkey', 'France', 'UK', 'Moldova']
data = [
('Canada', [1, 2, 1, 2, 1, 2, 1, 2]),
('Turkey', [2, 2, 2, 2, 0, 0, 1, 1]),
('France', [3, 2, 1, 3, 2, 1, 3, 2]),
('UK', [1, 1, 1, 0, 0, 0, 0, 1]),
('Moldova', [2, 3, 4, 1, 1, 2, 6, 9]),
]
x = []
y = []
size = []
alpha = []
for i in xrange(len(datasets)):
for j in xrange(len(buckets)):
dataset = datasets[i]
bucket = buckets[j]
x.append(dataset)
y.append(bucket)
# radii.append(data[i][1][j]*10)
# size.append(data[i][1][j]*0.1) # <-- Scaling for categorical display. See final cell in notebook.
size.append(0.8) # Fixed size
alpha.append(data[i][1][j]*0.1) # <-- alpha as a "intensity" measure.
line_alpha = [0.1 if a == 0 else a for a in alpha] # <-- to get borders over 0 "intensity" squares
This ColumnDataSource
object will also serve as the source for our hover tooltips. You can see an extended example in the Bokeh documentation.
source = ColumnDataSource(
data=dict(
x=x,
y=y,
size=size,
alpha=alpha, # <-- passed alpha to the source to be showed (later) by the hover tool
)
)
# draw it
figure()
visual_properties = {
'color': 'red', # <-- another color to try
'fill_alpha': alpha, # <-- alpha "defined" by our data
'line_color': 'red', # <-- add borders to the squares
'line_alpha': line_alpha, # <-- borders with the same alpha except for the 0 "intensity" square (cosmetic)
'plot_height': 1000,
'plot_width': 800,
'title': None,
}
rect('x', 'y', 'size', 'size',# <-- Passing "size" as width and height parameters from our `source`
source=source,
x_range=datasets,
y_range=buckets,
tools="hover", # <-- Added "hover" tool
marker="square",# <-- No it's not pretty, but there are (just now discovered) issues with
# hit-detection for the circle glyph on categorical axes.
**visual_properties)
grid().grid_line_color = None
This is how we currently get ahold of our hover tools. Yes it's a little clunky (for now), but at least it's a one-liner! :)
hover = [t for t in curplot().tools if isinstance(t, HoverTool)][0]
hover.tooltips = OrderedDict([
("Dataset", "@x"),
("Bucket", "@y"),
#("Size", "@size"),
("Alpha", "@alpha"),
])
hover
<bokeh.objects.HoverTool at 0x32482d0>
Then we make user of the OrderedDict
to declare the tooltip contents.
show()
As you can probably tell, the size no longer corresponds to screenspace pixel width and height, but rather scales against the column and row widths. So a size of (1, 1)
would indicate a rectangle that fills the intersection of that row and column completely.
I believe there is still work being done on combining screenspace/dataspace/categorical-space units in a natural manner. We would love your input!