使用散景绘图时如何为多个数据集之一添加悬停工具

我在 Python 中使用 Bokeh 绘制两个数据集。我将一个数据集绘制为一条线,另一个作为标记(圆圈十字)。我正在尝试为标记数据集添加一个悬停工具。


source = ColumnDataSource(df_bcn_rns)


p = figure(plot_height=300,

           plot_width=800,

           tools="",

           toolbar_location=None,

           x_axis_type='datetime',

           x_axis_location="above",

           background_fill_color="#efefef") #,x_range=(bcn_sp.index[-1], bcn_sp.index[0])


p.line(x=bcn_sp['Date'],

       y=bcn_sp['Close'])

#,source=source)


p.circle_cross(x='Date',

               y='price',

               source=source)


p.yaxis.axis_label = 'Closing Price'



p.add_tools(HoverTool(

        tooltips=[( 'date',   '@Date{%d-%m-%Y}'),

                  ( 'price',  '@price{00.2f}p'), # use @{ } for field names with spaces

                  ( 'rns header', '@Headline')],


        formatters={'Date' : 'datetime', # use 'datetime' formatter for 'date' field

                    'close' : 'printf'},   # use 'printf' formatter for 'adj close' field

        mode='vline' # display a tooltip whenever the cursor is vertically in line with a glyph

    ))


show(column(p)) #,select

上面的代码有效,但是,当鼠标悬停在任一数据集上时,悬停工具会显示。当鼠标悬停在线数据集上时,显示“???” 在悬停框中,我不希望它显示任何内容。


总而言之,我期望的结果是鼠标悬停在标记上时显示的悬停框,但只要鼠标悬停在行上时就没有悬停框,因为此数据集未链接到“源”。有什么建议我可以解决这个问题吗?


喵喔喔
浏览 188回答 1
1回答

阿波罗的战车

markers = p.circle_cross(...)返回一个markers渲染器,您需要将其指定为HoverTool. 在此处查看两个可能的选项
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python