散景中的可能更新导致了一个奇怪的生成器错误

Possible update in bokeh is causing a strange generator bug

我有以下代码片段在工作:

import numpy as np
import bokeh.plotting as bp
from bokeh.models import HoverTool 
bp.output_file('test.html')

fig = bp.figure(tools="reset,hover")
x = np.linspace(0,2*np.pi)
y1 = np.sin(x)
y2 = np.cos(x)
s1 = fig.scatter(x=x,y=y1,color='#0000ff',size=10,legend='sine')
s1.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
s2 = fig.scatter(x=x,y=y2,color='#ff0000',size=10,legend='cosine')
fig.select(dict(type=HoverTool)).tooltips = {"x":"$x", "y":"$y"}
bp.show()

没有线路 s1.select ... returns 生成器并给我以下错误:

AttributeError: 'generator' object has no attribute 'tooltips'

为 运行 此代码的进程发生了服务器更新。散景可能已更新。什么是我最快的解决方法?还是我遗漏了一个错误?

前段时间,字形方法更改为 return 字形渲染器,而不是绘图。这使得配置字形渲染器的视觉属性变得更加容易。返回绘图是多余的,因为用户通常已经有了对该绘图的引用。但是您想在绘图中搜索悬停工具,而不是字形渲染器,因此您需要执行以下操作:

fig.select(HoverTool).tooltips = {"x":"$x", "y":"$y"}

请注意,使用字典意味着无法保证工具提示的顺序。如果你关心顺序,你应该使用元组列表:

fig.select(HoverTool).tooltips = [("x", "$x"), ("y", "$y")]

然后工具提示行将按照给定的顺序从上到下显示。