import bokeh bokeh.print_versions() from bokeh.plotting import * from bokeh.objects import HoverTool from collections import OrderedDict output_notebook() #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) 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 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 ) ) labels = [tup[1] for tup in data] labels = [str(item) for sublist in labels for item in sublist] # draw it figure() hold() # <-- so we can add our new text renderer 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) text(x, y, text=labels, # <-- labels! text_color="black", angle=0) grid().grid_line_color = None hover = [t for t in curplot().tools if isinstance(t, HoverTool)][0] hover.tooltips = OrderedDict([ ("Dataset", "@x"), ("Bucket", "@y"), ("Alpha", "@alpha"), ]) show()