创建背景虚化的侧面板用于显示悬停的数据点的详细信息

问题描述 投票:0回答:2

我见过的背景虚化如何让你一个数据点悬停并显示弹出信息为它很好的例子。有案件的细节是如此巨大浩繁,它确实需要一个侧面板,以显示这一切。背景虚化是一个完整的足够小部件工具包,我可以创造一个侧板光标之后的数据点的主显示屏显示的细节?

有人能指出一些示例代码,或者至少是相关的API。

widget visualization bokeh
2个回答
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,输入“背景虚化的服务code.py --show”。


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)

sample

© www.soinside.com 2019 - 2024. All rights reserved.