如何说服visuals_at超越ViewBox?

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

我目前正在评估vispy,以满足我的交互式绘图需求。虽然感觉有点像beta,但它的速度给我留下了深刻的印象。同样在API设计方面,它看起来很有希望。

我需要工作的一个功能是用鼠标拾取绘图元素。分布(vispy)中有一个示例可以精确地做到这一点:0.6.4。不幸的是,它对我不起作用。

它将显示一个包含多行图形的窗口。我可以与整个图进行交互,即缩放和平移,但是我不能选择单个线。

如果我调试相关代码段(打印语句是我的代码,完整示例是examples/demo/scene/picking.py):

examples/demo/scene/picking.py

无论我在哪里单击,我都会获得at 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超越not well documented并找到实际的visuals_at实例?

python pyqt vispy
1个回答
0
投票

有一种解决方法,可以在调用visuals_at之前使视图变为非交互式。之后,可以再次将视图设置为交互式。

此解决方法可在google网上留言ViewBox中找到

该帖子来自2015年,所以这个问题似乎已经知道了一段时间。

代码

因此添加到代码中

LinePlot

在调用fig.visuals_at之前和之后执行

workaround

之后on_mouse_press的代码应如下所示:

plt.view.interactive = False

Test

plt.view.interactive = True

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