Python Bokeh-将Taptool分配给字形的子集 [英] Python Bokeh - Assign taptool to a subset of Glyphs

查看:28
本文介绍了Python Bokeh-将Taptool分配给字形的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在其中添加了一个圆形字形,代表两种不同类型的数据.

Hi have a timeserie to which I add circle glyphs, representing 2 different type of data.

我已经设法通过使用此处提出的建议为每个工具分配不同的工具提示: https://stackoverflow.com/a/37558475/4961888

I already managed to assign a different tooltip to each of them by using the suggestion presented here: https://stackoverflow.com/a/37558475/4961888

我希望我可以使用类似的语法将字形的特定子集分配给taptool,这样可以将我带到这些字形源中存在的url.

I was hoping I could use a similar syntax to assign a specific subset of the glyph to a taptool, that would bring me to a url present in the source of those glyphs.

所以我尝试了:

    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的方式不同,而且我在网络上找不到有关我的问题的任何文档.如果有人可以更好地抓紧包装,我会很高兴的.

It seems to me that the taptool has a different way of being assigned glyphs than the hovertool, and I couldn't find any documentation on the web regarding my problem. I would be glad if someone with a better grip of the package could help me wrap my head around it.

推荐答案

fig.select返回一个列表,因此您需要访问第一个(也是唯一的)元素.

fig.select returns a list, so you'll want to access the first (and only, I'd assume) element.

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)

OR

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)

这篇关于Python Bokeh-将Taptool分配给字形的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆