I have a simple graph of X-Y data points. I want my Bokeh figure to show me the integer value of each datapoint when I hover over it. I am close to getting what I want but when I hover over the data point, it shows a float and then higher up, it uses scientific notation. Is there a way to have the hover tool only return the integer values of X and Y and not use scientific notation?
Here is some example code:
from bokeh.plotting import *
from bokeh.models import HoverTool
x = range(1,101)
y = [i*i for i in x]
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select, hover"
p = figure(x_axis_label = "Days",
y_axis_label = "Return",
tools=TOOLS)
p.circle(x, y)
#adjust what information you get when you hover over it
hover = p.select(dict(type=HoverTool))
hover.tooltips = [
("Days", "$x"),
("Return", "$y"),
]
show(VBox(p))
Adding my two cents. I figured out by you can control the decimal points by using the following code:
hover.tooltips = [
("Days", "@x{int}"), # this will show integer, even if x is float
("Return", "@y{1.11}"), # this will format as 2-decimal float
]
Hope this helps.
Aha! Using @ instead of $ works.
hover.tooltips = [
("Days", "@x"),
("Return", "@y"),
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With