我想在绘图仪中向pyvista.PolyData
添加点(和单元格)。我尝试使用Plotter.update_coordinates
函数,但是这只对大小相同的点数据有用:
import numpy as np
import pyvista as pv
import pyvistaqt
points = np.array([[1, 0, 0],
[2, 0, 0],
[3, 0, 0]])
point_cloud = pv.PolyData(points)
plotter = pyvistaqt.BackgroundPlotter()
a = plotter.add_points(point_cloud)
plotter.show()
new_points = np.array([[1, 0, 0],
[2, 0, 0],
[5, 0, 0],
[7, 0, 0]]) # Not updated in the plotter
plotter.update_coordinates(new_points, point_cloud, render=True)
似乎这些点是更新的,但不是单元格。因此,在绘图仪中只有相应的单元格被修改。
更新PolyData的最佳实践是什么,其中包括新的(额外的)点?
发布于 2022-04-18 10:51:17
你说过
我想在绘图仪的
pyvista.PolyData
中添加点(和单元格)
但对我来说还不清楚。您有两个选项:要么向PolyData
添加进一步的点,然后绘制一个网格,要么将两个不同的PolyData
对象添加到同一个绘图仪中。
以下是两种选择:
import pyvista as pv
sphere_a = pv.Sphere()
sphere_b = sphere_a.translate((1, 0, 0), inplace=False)
# option 1: merge the PolyData
spheres = sphere_a + sphere_b
# alternatively: sphere_a += sphere_b for an in-place operation
spheres.plot() # plot the two spheres in one PolyData
# we could also use a Plotter for this
# option 2: add both PolyData to the same plotter
plotter = pv.Plotter()
plotter.add_mesh(sphere_a) # or add_points() for a point cloud
plotter.add_mesh(sphere_b)
plotter.show() # show the two spheres from two PolyData
另外,如果您只有点云(即没有单元格),您应该考虑使用the new PointSet
class。这需要PyVista 0.34.0和VTK9.1.0或更高版本。
https://stackoverflow.com/questions/71908957
复制相似问题