Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.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 如何在悬停时增加线段?_Python_Bokeh - Fatal编程技术网

Python 如何在悬停时增加线段?

Python 如何在悬停时增加线段?,python,bokeh,Python,Bokeh,我想在悬停时更改线段的线宽。我试图修改渲染器的悬停图示符,但它设置为None 示例1: from bokeh.plotting import figure, output_file, save p = figure() r = p.segment(x0=[1,2], y0=[2,3], x1=[10,20], y1=[20,30],line_width=3) r.hover_glyph.line_width = 6 output_file("hover.html") save(p) 给出了

我想在悬停时更改线段的线宽。我试图修改渲染器的悬停图示符,但它设置为
None

示例1:

from bokeh.plotting import figure, output_file, save

p = figure()
r = p.segment(x0=[1,2], y0=[2,3], x1=[10,20], y1=[20,30],line_width=3)
r.hover_glyph.line_width = 6

output_file("hover.html")
save(p)
给出了错误:

AttributeError:“非类型”对象没有“线宽”属性

编辑: 我使用的是Bokeh1.3.4

示例2:

from bokeh.plotting import figure, output_file, save

p = figure()
r = p.segment(x0=[1,2], y0=[2,3], x1=[10,20], y1=[20,30], line_width=3, hover_line_width=6)

output_file("hover.html")
save(p)
给出了错误:

AttributeError:分段的意外属性“悬停线宽度”,类似属性为线宽度

示例3:

from bokeh.plotting import figure, output_file, save
from bokeh.models import Segment

p = figure()
r = p.segment(x0=[1,2], y0=[2,3], x1=[10,20], y1=[20,30], line_width=3)
r.hover_glyph = Segment(x0=[1,2], y0=[2,3], x1=[10,20], y1=[20,30], line_width=6)

output_file("hover.html")
save(p)
给出了错误:

ValueError:应为字符串、Dict(枚举('expr','field','value','transform')、字符串、实例(transform)、实例(表达式)、Float)或Float的元素,获取[1,2]

编辑2: 最低限度的示例4起作用:

from bokeh.plotting import figure, output_file, save
from bokeh.models import Segment, HoverTool

p = figure()

r = p.segment(x0=[1,2], y0=[2,3], x1=[10,20], y1=[20,30], line_width=3)
p.add_tools(HoverTool(renderers=[r]))
r.hover_glyph = Segment(line_width=6)

output_file("hover.html")
save(p)

使用悬停图示符会增加开销,所以Bokeh不会自动创建它们,除非要求这样做。您试图在不存在的悬停图示符上设置属性。您可以:

  • 将便利参数值设置为

    p.segment(..., hover_line_width=6)
    
    Bokeh将接受此请求,并为您创建悬停图示符

  • 使用低级
    模型显式设置悬停图示符:

    r.hover_glyph = Segment(..., line_width=6)
    

有这两种技术的信息和示例。

我已经看过这些文档。你试过密码了吗?它不适用于我,请参见上面的编辑。您不能将文字数据列表/数组传递给低级glyph对象。它们只能配置为使用ColumnDataSource中的列。所有低级示例都证明了这一点。如果悬停参数不起作用,则这是段的一个怪癖,它缺少大多数图示符所具有的填充特性。(如果你是第一个尝试将鼠标悬停在段上的人)GitHub问题是合适的。就此而言,如果你看看我链接的文档中的示例,你会发现它们没有向低级glyph对象传递数据或列名,就像你正在尝试的那样。辅助图示符(如悬停或选择等)仅用于指定在这些情况下应使用的视觉特性。他们总是使用与主标志符相同的数据。对,我错过了!我已经使用glyphs很多次了,而且从来没有没有没有来源,所以在没有数据的情况下调用glyphs对我来说是完全陌生的。现在,如果我真的添加了悬停工具,它就可以工作了,请参见上面的示例4。非常感谢。很高兴它起作用了!请提出一个关于参数不起作用的问题,这将有助于在某个时候进行修复。