I'm trying to add a hover tooltop to a Bokeh pie chart made using wedge glyphs, but the hover tool shows multiple values for a given wedge. Is there a way to correct this? Code is:
import numpy as np
from bokeh.plotting import figure
from bokeh.io import show, output_file
from bokeh.models import HoverTool, ColumnDataSource
from math import pi
percents = [0, 5/143, 51/143, 88/143, 108/143, 141/143, 1.0]
category = ['A ', 'B ', 'C ', 'D ', 'E ', 'F']
counts = [5, 46, 37, 20, 33, 2]
starts = [1/2*pi-(p*2*pi) for p in percents[:-1]]
ends = [1/2*pi-(p*2*pi) for p in percents[1:]]
colors = ['#889dba', '#1f356f', '#1e92b8', '#33748a', '#a5d3e3', '#bbc2d4']
# create source
source = ColumnDataSource(
data=dict(
x=[0 for x in percents],
y=[0 for x in percents],
radius = [0.5 for x in percents],
percents=percents,
category= category,
starts=starts,
colors=colors,
ends=ends,
counts = counts
)
)
TOOLS = "hover"
p = figure(plot_width = 500, plot_height = 500, x_axis_label = None, y_axis_label = None,
title = 'Type', tools = TOOLS)
p.title.align = 'center'
p.title.text_font = 'arial narrow'
p.wedge(x='x', y='y', radius = 'radius', direction="clock",
start_angle='starts', end_angle='ends', color='colors', source=source)
hover = p.select(dict(type=HoverTool))
hover.tooltips = [
('category', '@category'),
('percents','@counts')
]
p.axis.visible = False
p.ygrid.visible = False
p.xgrid.visible = False
output_file(pie.html')
show(p)