I've built a flask app which is plotting several graphs in Bokeh.
The x values are datetime objects representing either days or weeks, and the y values are the value being tracked. There is a y value for each day, which is an integer.
I've added a hovertool to show the y value of the plot in the graph, the problem is that the hovertool shows a floating point value along the plotted line. I've plotted both in lines and circles for visual effect, but even when I remove the lines this is still true
The persons who will be using these graphs have asked if it were possible to show only whole numbers at the points which the data changes I tried to cast the yvalues as integers but that isn't what is driving how the hovertool gets it's values.
The other thing, if possible that I would like to change is to increase the font size of the text in the hovertool. I looked at the documentation at http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#hovertool and http://docs.bokeh.org/en/latest/docs/reference/models/tools.html but I have not been able to set that.
Here's the code for my hovertool
hover = HoverTool(tooltips=[
(title, "($y)")
Later....
fig = figure(plot_width=500,plot_height=500,title=title,x_axis_type='datetime',tools=[hover])
If you want to change the formatting of the values in a hover tool, you can specify a format when you specify each hover tool field. See: http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#formatting-tooltip-fields.
Here is an example with different formatting :
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool
output_file("toolbar.html")
source = ColumnDataSource(data=dict(
x=[1.8, 2, 3, 4, 5],
y=[2.2, 5, 8.234, 2, 7.22],
n_id=[1.8,2.8,2.2,2.4,2.5]))
hover = HoverTool(
tooltips=[
( 'x','$x{0}'),
( 'y','@y{0.0}'),
('id','@n_id{0}')
],
)
p = figure(plot_width=400, plot_height=400, tools=[hover],
title="Mouse over the dots")
p.circle('x', 'y', size=20, source=source)
show(p)
If you want more control over the appearance, you need to write a custom tooltip : http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#custom-tooltip
You can use that and combine the formatters like so:
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool
output_file("toolbar.html")
source = ColumnDataSource(data=dict(
x=[1.8, 2, 3, 4, 5],
y=[2.2, 5, 8.234, 2, 7.22],
n_id=[1.8,2.8,2.2,2.4,2.5]))
hover = HoverTool(
tooltips="""
<div>
<div>
<span style="font-size: 17px; font-weight: bold;">x: @x{0.0}</span>
</div>
<div>
<span style="font-size: 15px; color: #966;">y: @y{0.00}</span>
</div>
<div>
<span style="font-size: 23px; color: #966;">id: @n_id{0}</span>
</div>
</div>
"""
)
p = figure(plot_width=400, plot_height=400, tools=[hover],
title="Mouse over the dots")
p.circle('x', 'y', size=20, source=source)
show(p)