我目前正在评估vispy
我的交互式绘图需求。虽然它感觉有点像测试版,但我对它的速度印象深刻。从 API 设计的角度来看,它看起来很有希望。
我需要使用的一项功能是用鼠标选择绘图元素。分布 ( 0.6.4
) 中的一个示例承诺准确地做到这一点:examples/demo/scene/picking.py
. 不幸的是,它对我不起作用。
它显示一个包含多条线图的窗口。我可以与整个情节进行交互,即缩放和移动,但我不能选择单独的线条。
如果我对相关的代码进行猴子调试(打印语句是我的,完整的例子在 github):
@fig.connect
def on_mouse_press(event):
global selected, fig
if event.handled or event.button != 1:
return
if selected is not None:
selected.set_data(width=1)
selected = None
for v in fig.visuals_at(event.pos):
print(v)
if isinstance(v, vp.LinePlot):
selected = v
break
if selected is not None:
selected.set_data(width=3)
update_cursor(event.pos)
<ViewBox at 0x...>
无论我点击哪里,我都会得到。fig
是一个没有很好记录vispy.plot.Fig
的实例。
我怎样才能使这项工作,即visuals_at
超越ViewBox
并找到实际LinePlot
实例?