【问题标题】:Retrieve data on mouse click in Mayavi在 Mayavi 中通过鼠标点击检索数据
【发布时间】:2017-01-18 09:46:31
【问题描述】:

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

【问题讨论】:

    标签: python python-2.7 mouseclick-event mayavi


    【解决方案1】:

    这是来自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()
    

    希望对某人有所帮助,在数组中获取点索引的划分很有趣;)

    【讨论】:

    • 是的,点索引很有趣!感谢您修复获取示例中的索引以使用楼层划分。
    猜你喜欢
    • 2013-05-16
    • 2017-11-23
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 2013-12-08
    相关资源
    最近更新 更多