2017-07-06 182 views
1

我想讓散景懸停工具捕捉到數據點,而不是在線上插入鼠標位置。以下是我認爲會這樣做的代碼,但我仍然在顯示中獲取插值數據。如何獲取散景懸停工具以捕捉數據?

from bokeh.plotting import figure, output_file, show 
from bokeh.models import HoverTool 

# prepare some data 
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0] 
y0 = [i**2 for i in x] 
y1 = [10**i for i in x] 
y2 = [10**(i**2) for i in x] 

# output to static HTML file 
output_file("log_lines.html") 

hover = HoverTool(tooltips=[ 
    ("index", "$index"), 
    ("(x,y)", "(@x, @y)"), 
    ("desc", "@desc"), 
]) 
hover.point_policy='snap_to_data' 
hover.line_policy='none' 

# create a new plot 
p = figure(
    tools="pan,box_zoom,reset,save,hover", 
    y_axis_type="log", y_range=[0.001, 10**11], title="log axis example", 
    x_axis_label='sections', y_axis_label='particles' 
) 

# add some renderers 
p.line(x, x, legend="y=x") 
p.circle(x, x, legend="y=x", fill_color="white", size=8) 
p.line(x, y0, legend="y=x^2", line_width=3) 
p.line(x, y1, legend="y=10^x", line_color="red") 
p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6) 
p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4") 

# show the results 
show(p) 

回答

1

您沒有將您的自定義HoverTool實例傳遞給圖。您需要做:

... 
p = figure(tools="pan,box_zoom,reset,save", 
      y_axis_type="log", y_range=[0.001, 10**11], title="log axis example", 
      x_axis_label='sections', y_axis_label='particles') 
p.add_tools(hover) # this is your custom HoverTool 
... 
相關問題