我看到了许多很好的示例,这些示例说明bokeh如何使您将鼠标悬停在数据点上并显示其弹出的详细信息。在某些情况下,细节如此庞大,以至于它确实需要一个侧面板来显示所有内容。 bokeh是否是一个足够完整的窗口小部件工具箱,我可以在其中创建主显示屏的侧面板并显示光标后的数据点的详细信息?
有人可以指出一些示例代码,或者至少指出相关的api。
答案 0 :(得分:0)
您可以在https://bokeh.pydata.org上找到许多示例。通过添加回调并更新相关部分,可以实现所需的功能。在此示例中,div是您在问题中命名为侧面板的名称。
#for bokeh 1.0.4
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource,Div,Row
from bokeh.io import curdoc
from bokeh.events import Tap
#the data
d={'x':[1,2],'y':[3,4],'info':['some information on a first datapoint','some information on a second datapoint']}
source=ColumnDataSource(d)
tooltips = [("x", "$x"),("y", "$y"),("info","@info")]
fig=figure(tools="tap,reset",tooltips=tooltips)
c=fig.circle('x','y',source=source,size=15)
def callback(event):
indexActive=source.selected.indices[0]
layout.children[1]=Div(text=d['info'][indexActive])#adjust the info on the right
fig.on_event(Tap, callback)
div=Div(text=d['info'][0])
layout=Row(fig,div)
curdoc().add_root(layout)
要运行此代码,请将其另存为code.py,打开一个cmd并键入“ bokeh serve code.py --show”。
答案 1 :(得分:0)
如果您希望使用更高级别的API来构建和链接基于散景的图,则可以使用HoloViews。请参阅http://holoviews.org/reference/index.html#streams的链接示例和http://holoviews.org/user_guide/Custom_Interactivity.html的说明。例如:
import param, numpy as np, holoviews as hv
from holoviews import opts, streams
hv.extension('bokeh')
xvals = np.linspace(0,4,202)
ys,xs = np.meshgrid(xvals, -xvals[::-1])
img = hv.Image(np.sin(((ys)**3)*xs))
pointer = streams.PointerXY(x=0,y=0, source=img)
dmap = hv.DynamicMap(lambda x, y: hv.Points([(x, y)]), streams=[pointer])
dmap = dmap.redim.range(x=(-0.5,0.5), y=(-0.5,0.5))
img + dmap.opts(size=10)