Python Bokeh - 将 taptool 分配给 Glyphs 的子集
Python Bokeh - Assign taptool to a subset of Glyphs
你好有一个时间序列,我在其中添加了圆形字形,代表 2 种不同类型的数据。
我已经使用此处提出的建议设法为每个工具分配了不同的工具提示:
我希望我可以使用类似的语法将字形的特定子集分配给 taptool,这会把我带到这些字形源中的 url。
所以我尝试了:
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
但我收到:
AttributeError: '_list_attr_splat' object has no attribute 'renderers'
在我看来,taptool 分配字形的方式与 hovertool 不同,而且我在网上找不到任何关于我的问题的文档。如果有人能更好地掌握包裹,我会很高兴能帮助我绕过它。
fig.select
returns 一个列表,因此您需要访问第一个(我假设也是唯一一个)元素。
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)[0]
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
或
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select_one(TapTool)
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
如果您使用的是 bokeh 0.13.0,您可以通过将渲染器分配为列表来实现此目的。而不是 taptool.renderers.append(glyph)
你可以做 taptool.renderers= [glyph,]
沿线的东西
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5,
source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)[0]
taptool.renderers= [news_points,]
taptool.callback = OpenURL(url=url)```
否则你可能会得到一个额外的错误str has no attribute append
从 documentation 渲染器也可以接受一个列表,这在图表上有多个渲染器时尤为重要,否则它会占用绘图上的所有渲染器。
你好有一个时间序列,我在其中添加了圆形字形,代表 2 种不同类型的数据。
我已经使用此处提出的建议设法为每个工具分配了不同的工具提示:
我希望我可以使用类似的语法将字形的特定子集分配给 taptool,这会把我带到这些字形源中的 url。
所以我尝试了:
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
但我收到:
AttributeError: '_list_attr_splat' object has no attribute 'renderers'
在我看来,taptool 分配字形的方式与 hovertool 不同,而且我在网上找不到任何关于我的问题的文档。如果有人能更好地掌握包裹,我会很高兴能帮助我绕过它。
fig.select
returns 一个列表,因此您需要访问第一个(我假设也是唯一一个)元素。
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)[0]
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
或
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5, source=news_source)
url = "@url"
taptool = fig.select_one(TapTool)
taptool.renderers.append(news_points)
taptool.callback = OpenURL(url=url)
如果您使用的是 bokeh 0.13.0,您可以通过将渲染器分配为列表来实现此目的。而不是 taptool.renderers.append(glyph)
你可以做 taptool.renderers= [glyph,]
沿线的东西
fig = figure(x_axis_type="datetime", height=200, tools="tap")
fig.line(x_range, y_range)
news_points = fig.circle(x='timestamp', y='y', fill_color="green", size=5,
source=news_source)
url = "@url"
taptool = fig.select(type=TapTool)[0]
taptool.renderers= [news_points,]
taptool.callback = OpenURL(url=url)```
否则你可能会得到一个额外的错误str has no attribute append
从 documentation 渲染器也可以接受一个列表,这在图表上有多个渲染器时尤为重要,否则它会占用绘图上的所有渲染器。