简体   繁体   English

如何在散景中使用悬停工具提示显示整数,而不是浮点数

[英]how to show integer, not float, with hover tooltip in bokeh

I have a simple graph of XY data points. 我有一个简单的XY数据点图。 I want my Bokeh figure to show me the integer value of each datapoint when I hover over it. 当我将鼠标悬停在它上面时,我希望我的Bokeh图形显示每个数据点的整数值。 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? 有没有办法让悬停工具只返回X和Y的整数值而不使用科学记数法?

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"),
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM