Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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打印中_Python_Hover_Bokeh - Fatal编程技术网

Python 悬停工具显示'';在模板渲染后的bokeh打印中

Python 悬停工具显示'';在模板渲染后的bokeh打印中,python,hover,bokeh,Python,Hover,Bokeh,在以这种方式渲染绘图后,我似乎无法让鼠标悬停工具显示圆形图示符的信息(下面的代码)。鼠标悬停工具弹出,但每个工具提示都显示“?”,而不是ColumnDataSource中的信息。任何帮助都将不胜感激 from jinja2 import Template from bokeh.models import HoverTool, ColumnDataSource, BoxSelectTool, GeoJSONDataSource from bokeh.core.templa

在以这种方式渲染绘图后,我似乎无法让鼠标悬停工具显示圆形图示符的信息(下面的代码)。鼠标悬停工具弹出,但每个工具提示都显示“?”,而不是ColumnDataSource中的信息。任何帮助都将不胜感激

from jinja2 import Template

from bokeh.models import HoverTool, ColumnDataSource, BoxSelectTool,             GeoJSONDataSource
from bokeh.core.templates import CSS_RESOURCES, JS_RESOURCES
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.resources import INLINE
from bokeh.util.string import encode_utf8


source = ColumnDataSource(
    data=dict(
        x=[1, 2, 3, 4, 5],
        y=[2, 5, 8, 2, 7],
        desc=['A', 'b', 'C', 'd', 'E'],
    )
)

hover = HoverTool(

    tooltips=[
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
        ("desc", "@desc"),
    ]
)

p = figure(plot_width=400, plot_height=400,
       title="Mouse over the dots")

g1 = p.circle('x', 'y', size=20, source=source)

hover = HoverTool(
    renderers= [g1],
    tooltips=[
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
        ("desc", "@desc"),
    ]
)
p.add_tools(hover)

js_resources = JS_RESOURCES.render(
    js_raw=INLINE.js_raw,
    js_files=INLINE.js_files
)

css_resources = CSS_RESOURCES.render(
    css_raw=INLINE.css_raw,
    css_files=INLINE.css_files
)

script, div = components(p, INLINE)
template = Template('''<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Bokeh Scatter Plots</title>
        {{ js_resources }}
        {{ css_resources }}
        {{ script }}
    </head>
    <body>
            {{ div }}
    </body>
</html>
''')
html = template.render(
    js_resources=js_resources,
    css_resources=css_resources,
    script=script,
    div=div
)

filename='toolTipPrac.html'
with open(filename, 'w') as f:
    f.write(html)
来自jinja2导入模板的

从bokeh.models导入HoverTool、ColumnDataSource、BoxSelectTool、GeoJSONDataSource
从bokeh.core.templates导入CSS_资源、JS_资源
从bokeh.embed导入组件
从bokeh.plotting导入图形
从bokeh.resources内联导入
从bokeh.util.string导入编码
source=ColumnDataSource(
数据=dict(
x=[1,2,3,4,5],
y=[2,5,8,2,7],
desc=['A','b','C','d','E'],
)
)
悬停=悬停工具(
工具提示=[
(“指数”、“美元指数”),
("x,y","(x元,y元),,
(“描述”,“描述”),
]
)
p=图形(绘图宽度=400,绘图高度=400,
title=“鼠标悬停在点上”)
g1=p.circle('x','y',尺寸=20,震源=震源)
悬停=悬停工具(
渲染器=[g1],
工具提示=[
(“指数”、“美元指数”),
("x,y","(x元,y元),,
(“描述”,“描述”),
]
)
p、 添加工具(悬停)
js_resources=js_resources.render(
js_raw=INLINE.js_raw,
js_files=INLINE.js_文件
)
css\u resources=css\u resources.render(
css_raw=INLINE.css_raw,
css\u文件=INLINE.css\u文件
)
脚本,div=组件(p,内联)
模板=模板(“”)
博克散点图
{{js_resources}}
{{css_resources}}
{{script}}
{{div}}
''')
html=template.render(
js_resources=js_resources,
css_resources=css_resources,
脚本=脚本,
div=div
)
filename='toolTipPrac.html'
将open(filename,'w')作为f:
f、 编写(html)

example:您的示例在
0.11.1
build上对我有用。你用的是什么版本的bokeh
bokeh.\uuuu版本\uuuuu
它也可以在
master
上工作。这很奇怪,因为我也在0.11.1版本上@b Collins什么版本的Python/Browser/OS?我使用的是Python 3.5/Chrome/OSXexample:您的示例在
0.11.1
构建中对我起到了作用。你用的是什么版本的bokeh
bokeh.\uuuu版本\uuuuu
它也可以在
master
上工作。这很奇怪,因为我也在0.11.1版本上@b Collins什么版本的Python/Browser/OS?我使用的是Python 3.5/Chrome/OSX