You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在UnstructuredGrid外调用PyVista Plotter类的各类方法?

解决PyVista中UnstructuredGrid调用Plotter类方法的问题

当然可以使用enable_point_picking这类Plotter类的方法,只是不能直接通过UnstructuredGrid实例调用。grid.plot()是PyVista提供的快捷绘图方式,内部会自动创建一个临时的Plotter实例,但这个实例不会暴露给你操作。要使用Plotter的交互方法,你需要手动创建Plotter对象,步骤如下:

具体实现步骤

  • 手动初始化Plotter实例
  • 将你的UnstructuredGrid添加到Plotter中
  • 调用enable_point_picking开启点选择功能
  • 启动绘图窗口

示例代码:

import pyvista as pv

# 假设你的UnstructuredGrid已经创建好,命名为grid
grid = pv.UnstructuredGrid(...)  # 你的网格数据

# 1. 创建Plotter实例
plotter = pv.Plotter()

# 2. 添加网格到Plotter
plotter.add_mesh(grid)

# 3. 开启点选择功能,可自定义回调函数处理选中的点
def pick_callback(point_id):
    print(f"选中的点ID: {point_id}")

plotter.enable_point_picking(callback=pick_callback, show_message=True)

# 4. 显示绘图窗口
plotter.show()

额外说明

  • enable_point_picking支持多个参数自定义交互行为,比如设置pickable指定可选择元素类型、tolerance调整选择精度等,你可以根据需求调整。
  • 如果需要选择单元格而非点,可以使用enable_cell_picking方法,用法类似。

内容的提问来源于stack exchange,提问作者man-teiv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 04:44:55