首页 > 解决方案 > 如何仅在散景多线图中仅显示行光标打开的悬停工具提示?

问题描述

因此,我绘制并显示了各种行的悬停工具提示,如下所示:

def plotter(results, title):

    results = results.rename(columns = dict(zip(results.columns, [col.strip().replace(' ','_') for col in results.columns])))
    source = ColumnDataSource(results)
    p = figure(plot_width=600, plot_height=300)
    
    for color, col in enumerate(results.columns):
        

        glyph = Circle(x='month', y=col,
                 #source=source,
                 size=3, line_color=Turbo256[color*5], fill_color = Turbo256[color*5])
        p.add_glyph(source, glyph)
        p.line(x='month', y = col, source = source, color = Turbo256[color*5], line_width = 1)

    p.title.text = f"Monthly rates trends Based on {title.replace('_',' ').title()} "
    p.xaxis.axis_label = 'Months'
    p.yaxis.axis_label = 'Rates'

    hover=HoverTool(show_arrow=False, line_policy='next', tooltips = [
        (col.replace('_',' ').title(), f'@{col}') for col in results.columns] )   
    
    p.add_tools(hover)

    show(p)

虽然这很好用,但每当我将一个点悬停在图表上时,它都会显示每条线的工具提示。我不想显示所有的工具提示。我只希望这些工具提示显示当前所在的光标。就像它在一行上只有一个关于该行的工具提示应该显示,如果它在有两行的某个点上,它可能会显示两个的工具提示,依此类推。我一直在尝试使用CustomJS,但还没有想出办法。任何有关这方面的帮助都将非常有帮助。

标签: pythonplotbokehmultiline

解决方案


推荐阅读