在Mayavi中单击鼠标时检索数据

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

我已经开发了一个代码,其中绘制了散点图,并且在点击特定的散点图时,我可以使用text3d添加文本/标签。但现在我想使用on_mouse_pick回调从该图上的任何点恢复或检索该数据,并在控制台中打印该数据。我想在Mayavi / Mayavi2中这个。这可能吗?

python python-2.7 mouseclick-event mayavi
1个回答
0
投票

这是来自http://docs.enthought.com/mayavi/mayavi/auto/example_select_red_balls.html的例子。

glyphs = mlab.points3d(x, y, z, s, colormap="RdYlBu", scale_factor=1, scale_mode='none')
glyph_points = glyphs.glyph.glyph_source.glyph_source.output.points.to_array()

print(len(s))

def picker_callback(picker):
    if picker.actor in glyphs.actor.actors:
        point_id = picker.point_id//glyph_points.shape[0]
        if point_id != -1:
            print("{}:".format(point_id))
            print("({} {} {}) ".format(x[point_id],y[point_id],z[point_id]))

picker = figure.on_mouse_pick(picker_callback)
mlab.show()

希望有帮助,分区得到数组中的点索引是相当有趣的;)

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