Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多重线图中的Bokeh hovertool_Python_Bokeh - Fatal编程技术网

Python 多重线图中的Bokeh hovertool

Python 多重线图中的Bokeh hovertool,python,bokeh,Python,Bokeh,我是bokeh的新手,我刚开始使用hovertool,这就是为什么我想首先使用bokeh。 现在我正在绘制基因图,我想要实现的是多条具有相同y坐标的线,当你悬停在一条线上时,你会得到这个基因的名称和位置 我试着模仿这个例子,但由于某种原因,我甚至不能让它显示坐标 我确信,如果有人真的了解博克的情况,看到这段代码,错误就会很明显,如果他们给我看,我会非常感激 from bokeh.plotting import figure, HBox, output_file, show, VBox, Colu

我是bokeh的新手,我刚开始使用hovertool,这就是为什么我想首先使用bokeh。 现在我正在绘制基因图,我想要实现的是多条具有相同y坐标的线,当你悬停在一条线上时,你会得到这个基因的名称和位置

我试着模仿这个例子,但由于某种原因,我甚至不能让它显示坐标

我确信,如果有人真的了解博克的情况,看到这段代码,错误就会很明显,如果他们给我看,我会非常感激

from bokeh.plotting import figure, HBox, output_file, show, VBox, ColumnDataSource
from bokeh.models import Range1d, HoverTool
from collections import OrderedDict
import random

ys = [10 for x in range(len(levelsdf2[(name, 'Start')]))]
xscale = zip(levelsdf2[('Log', 'Start')], levelsdf2[('Log', 'Stop')])
yscale = zip(ys,ys)

TOOLS="pan,wheel_zoom,box_zoom,reset,hover"
output_file("scatter.html")
hover_tips = levelsdf2.index.values
colors = ["#%06x" % random.randint(0,0xFFFFFF) for c in range(len(xscale))]

source = ColumnDataSource(
    data=dict(
        x=xscale,
        y=yscale,
        gene=hover_tips,
        colors=colors,
    )
)


p1 = figure(plot_width=1750, plot_height=950,y_range=[0, 15],tools=TOOLS)
p1.multi_line(xscale[1:10],yscale[1:10], alpha=1, source=source,line_width=10, line_color=colors[1:10])

hover = p1.select(dict(type=HoverTool))
hover.tooltips = [
    ("index", "$index"),
    ("(x,y)", "($x, $y)"),
]

show(p1)

如果重要的话,
levelsdf2
是一个pandas.DataFrame。

我自己想出来的。原来Bokeh的0.8.2版本不允许对线使用hovertool,所以我使用quads做了同样的事情

from bokeh.plotting import figure, HBox, output_file, show, VBox, ColumnDataSource
from bokeh.models import Range1d, HoverTool
from collections import OrderedDict
import random


xscale = zip(levelsdf2[('series1', 'Start')], levelsdf2[('series1', 'Stop')])
xscale2 = zip(levelsdf2[('series2', 'Start')], levelsdf2[('series2', 'Stop')])
yscale2 = zip([9.2 for x in range(len(levelsdf2[(name, 'Start')]))],[9.2 for x in range(len(levelsdf2[(name, 'Start')]))])

TOOLS="pan,wheel_zoom,box_zoom,reset,hover"
output_file("linesandquads.html")
hover_tips = levelsdf2.index.values
colors = ["#%06x" % random.randint(0,0xFFFFFF) for c in range(len(xscale))]
proc1 = 'Log'
proc2 = 'MazF2h'
expression1 = levelsdf2[(proc1, 'Level')]
expression2 = levelsdf2[(proc2, 'Level')]
source = ColumnDataSource(
    data=dict(
        start=[min(xscale[x]) for x in range(len(xscale))],
        stop=[max(xscale[x]) for x in range(len(xscale))],
        start2=[min(xscale2[x]) for x in range(len(xscale2))],
        stop2=[max(xscale2[x]) for x in range(len(xscale2))],
        gene=hover_tips,
        colors=colors,
        expression1=expression1,
        expression2=expression2,

    )
)


p1 = figure(plot_width=900, plot_height=500,y_range=[8,10.5],tools=TOOLS)
p1.quad(left="start", right="stop", top=[9.211 for x in range(len(xscale))],
        bottom = [9.209 for x in range(len(xscale))], source=source, color="colors")

p1.multi_line(xscale2,yscale2, source=source, color="colors", line_width=20)


hover = p1.select(dict(type=HoverTool))

hover.tooltips = OrderedDict([
    (proc1+" (start,stop, expression)", "(@start| @stop| @expression1)"),

    ("Gene","@gene"),
])

show(p1)
工作起来很有魅力

编辑:根据请求添加结果图片,并编辑代码以匹配发布的屏幕截图

这不是最好的解决方案,因为事实证明,在一个图上绘制多个四边形序列并不那么容易。这可能是有可能的,但在我的用例中,这并不重要,所以我没有进行太多的调查

由于所有的基因都在同一个位置的所有序列上显示,我只是在四元图中添加了所有序列的工具提示,并在同一个图上绘制了另一个序列的多线图


这意味着,如果您将鼠标悬停在9.21的顶行上,您也会得到9.2行的工具提示,但是如果您将鼠标悬停在9.2行上,您根本不会得到工具提示。

您还可以发布绘图的图片吗。因为在我看来,从代码中解释它很难。我现在也面临同样的情况。这个问题对我来说是个救命稻草。它会不会是一个简单地绘制多条单行线的选项,例如,在这个代码片段中给出的?