为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

喵喔喔 2022-06-28 17:16:37
我在 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上面的代码有效,但是,当鼠标悬停在任一数据集上时,悬停工具会显示。当鼠标悬停在线数据集上时,显示“???” 在悬停框中,我不希望它显示任何内容。总而言之,我期望的结果是鼠标悬停在标记上时显示的悬停框,但只要鼠标悬停在行上时就没有悬停框,因为此数据集未链接到“源”。有什么建议我可以解决这个问题吗?
查看完整描述

1 回答

?
阿波罗的战车

TA贡献1862条经验 获得超6个赞

markers = p.circle_cross(...)返回一个markers渲染器,您需要将其指定为HoverTool在此处查看两个可能的选项



查看完整回答
反对 回复 2022-06-28
  • 1 回答
  • 0 关注
  • 187 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号