在以这种方式渲染绘图之后,我似乎无法让HoverTool显示圆形字形的信息(下面的代码)。 hovertool弹出,但每个工具提示显示' ???'而不是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)