我有几个网格,每个都是用pyvista读取的。
import pyvista as pv
# read the data
grid1 = pv.read('mesh1.vtk')
grid2 = pv.read('mesh2.vtk')我想要将它们一起绘制在具有不同颜色的相同图上:
plotter = pv.Plotter(window_size=(1500, 1100))
plotter.add_mesh(grid1, color=[0.6, 0.2, 0.1])
plotter.add_mesh(grid2, color=[0.1, 0.6, 0.6])我可以为每个网格添加标签吗?或者添加图例?
发布于 2020-07-29 09:36:49
是的,这是自然可以做到的,而且您已经知道必须使用的关键字:label和legend
import pyvista as pv
from pyvista import examples
unstructured = examples.load_hexbeam()
poly = examples.load_ant()
poly.points /= 10
poly.points += [0, 2, 3]
plotter = pv.Plotter()
plotter.add_mesh(unstructured, color=[0.6, 0.2, 0.1], label='beamy')
plotter.add_mesh(poly, color=[0.1, 0.6, 0.6], label='anty')
plotter.add_legend()
plotter.show()

正如您所看到的,作为add_mesh的label关键字参数传递的字符串将转换为图例中的标签,您可以使用add_legend()调用启用该图例。用于图例see the documentation的自定义选项。
https://stackoverflow.com/questions/62877969
复制相似问题