散景中的多行悬停 [英] multi_line hover in bokeh

查看:77
本文介绍了散景中的多行悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此问题中:

Bokeh multi_line和HoverTool

我发现hovertool不能用于多线图,这有点挫折.此处在警告"下提到了此问题: http://docs.bokeh.org/en/0.11.0/docs/reference/models/tools.html#bokeh.models.tools.HoverTool

I found that hovertool is not implemented for multi_line plots which is a bit of a setback. This is mentioned under 'warnings' here: http://docs.bokeh.org/en/0.11.0/docs/reference/models/tools.html#bokeh.models.tools.HoverTool

对此有任何解决方法吗? 另外,如果我要实现此功能,那么什么地方是一个不错的起点,还有什么需要注意的地方? 另外,当前的Bokeh路线图中是否有此功能?

Is there any work arounds for this? Also, If I were to implement this feature, what would be a good place to start and is there anything specific to be aware of? Also, is this feature in the current Bokeh roadmap?

推荐答案

从Bokeh 0.12.4开始(实际上是,但我忘记了确切的版本),悬停工具支持mutli_line:

As of Bokeh 0.12.4 (earlier, actually but I forget the exact release) the hover tool supports mutli_line:

from collections import defaultdict

import numpy as np
from scipy.stats import norm

from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.palettes import Viridis6

RT_x = np.linspace(118, 123, num=50)

mass_spec = defaultdict(list)
for scale, mz in [(1.0, 83), (0.9, 55), (0.6, 98), (0.4, 43), (0.2, 39), (0.12, 29)]:
    mass_spec["RT"].append(RT_x)
    mass_spec["RT_intensity"].append(norm(loc=120.4).pdf(RT_x) * scale)
    mass_spec['MZ_tip'].append(mz)
    mass_spec['Intensity_tip'].append(scale)
mass_spec['color'] = Viridis6

source = ColumnDataSource(mass_spec)

p = figure(plot_height=400)
p.multi_line(xs='RT', ys='RT_intensity', legend="Intensity_tip",
             line_width=5, line_color='color', line_alpha=0.6,
             hover_line_color='color', hover_line_alpha=1.0,
             source=source)

p.add_tools(HoverTool(show_arrow=False, line_policy='next', tooltips=[
    ('MZ', '@MZ_tip'),
    ('Rel Intensity', '@Intensity_tip')
]))

show(p)

会导致

这篇关于散景中的多行悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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