使用pyvista绘制多个网格

2024-05-15 03:48:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有几个网格,我使用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])

我可以为每个网格添加标签吗?还是添加图例


Tags: theimportadd网格readdataascolor
1条回答
网友
1楼 · 发布于 2024-05-15 03:48:48

是的,这自然可以做到,而且您已经知道必须使用的关键字:labellegend

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()             

Plot with a beam and an ant, both with their labels in a legend

正如您所看到的,作为add_meshlabel关键字参数传递的字符串变成了图例中的标签,您可以通过add_legend()调用启用这些标签。用于图例see the documentation的自定义选项

相关问题 更多 >

    热门问题