multi_line悬停在散景

时间:2016-07-11 10:32:34

标签: python visualization jupyter-notebook bokeh

如同这个问题:

Bokeh multi_line and HoverTool

我发现hovertool没有用于multi_line图,这有点像挫折。这是在'警告'中提到的。在这里:http://bokeh.pydata.org/en/0.11.0/docs/reference/models/tools.html#bokeh.models.tools.HoverTool

这有什么工作吗? 另外,如果我要实现这个功能,那么什么是一个好的起点,是否有任何具体要注意的地方? 此外,当前的散景路线图中是否有此功能?

1 个答案:

答案 0 :(得分:10)

截至Bokeh 0.12.4(之前,实际上我忘了确切的发布),悬停工具支持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)

结果是

enter image description here