Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bokeh confusion matrix plot bug
#cf https://groups.google.com/a/continuum.io/forum/#!msg/bokeh/rvFcJV5_WQ8/Pf5hsF9mCAAJ
from collections import OrderedDict
import numpy as np
from bokeh.plotting import figure, show, output_file
from bokeh.models import HoverTool, ColumnDataSource
N = 20
arr2d = np.random.randint(0,10,size=(N,N))
predicted = []
actual = []
count = []
color = []
alpha = []
the_color = '#cc0000'
for col in range(N):
for rowi in range(N):
predicted.append(str(rowi))
actual.append(str(col))
count.append(arr2d[rowi,col])
a = arr2d[rowi,col]/10.0
alpha.append(a)
color.append(the_color)
source = ColumnDataSource(
data=dict(predicted=predicted, actual=actual, count=count, alphas=alpha, colors=color)
)
p = figure(title='Confusion Matrix',
x_axis_location="above", tools="resize,hover,save",
y_range=list(reversed(actual)), x_range=actual)
p.plot_width = 600
p.plot_height = p.plot_width
rectwidth = 10.9
p.rect('predicted', 'actual', rectwidth, rectwidth, source=source,
color='colors', alpha='alphas',line_width=1, line_color='k')
p.axis.major_label_text_font_size = "12pt"
p.axis.major_label_standoff = 1
p.xaxis.major_label_orientation = np.pi/3
hover = p.select(dict(type=HoverTool))
hover.tooltips = OrderedDict([
('predicted', '@predicted'),
('actual', '@actual'),
('count', '@count'),
])
show(p)
@rcompton

This comment has been minimized.

Copy link
Owner Author

rcompton commented Dec 10, 2015

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.