散景-如何使悬停工具仅适用于特定点?

DS-V

我有以下代码:

bk.reset_output()
bk.output_notebook()
source1 = ColumnDataSource(data=dict(x=xnew, y=y_smooth))
source2 = ColumnDataSource(data=dict(x=xmax, y=ymax, desc=xmax, imgs = ['../Documents/cat.jpeg',
                                                                    '../Documents/lebowski.jpg']))

# create a new plot with a title and axis labels
p = bk.figure(plot_width=500, plot_height=500, title='foobar')
# add a line and a Hover tool that will display the value of x and y at any point along the line
#p.line(x='CCS', y='Intensity', line_width=2, source=source)

    p.add_tools(HoverTool(
    tooltips="""
    <div>
        <span style="font-size: 17px; font-weight: bold;">@desc</span>
    </div>
         <img
                src="@imgs" height="100" alt="@imgs" width="100"
                style="float: left; margin: 0px 15px 15px 0px;"
                border="2"
            ></img>
            """
))

p.scatter(x='x', y='y', source=source2, marker="inverted_triangle", size=12)
p.line(x='x', y='y', source=source1)
p.xaxis.axis_label = 'CCSD'
p.yaxis.axis_label = 'Intensity'
# show the results
show(p)

它给了我这张图:

在此处输入图片说明

如您所见,我有一个重叠部分。我只希望有一个对应于三角形的弹出窗口(它包括图像),相反,它为沿线的每个点以及三角形都提供了一个弹出框,因此为什么我会得到一个????弹出。从本质上讲,我只希望将悬停工具用于p.scatter图,而不同时用于两者。有一些可行的方法吗?

我是Bokeh和程序设计的新手,所以感觉很卡住。

帕利

为需要悬停工具的字形命名:

p.scatter(x='x', y='y', source=source2, marker="inverted_triangle", size=12, name='needshover')

制作悬停工具并将其指向字形:

hover = HoverTool(names=['needshover'], tooltips="""
    <div>
        <span style="font-size: 17px; font-weight: bold;">@desc</span>
    </div>
         <img
                src="@imgs" height="100" alt="@imgs" width="100"
                style="float: left; margin: 0px 15px 15px 0px;"
                border="2"
            ></img>
          """))

添加悬浮工具:

p.add_tools(hover)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章