построение нескольких сеток с помощью pyvista - PullRequest
0 голосов
/ 13 июля 2020

У меня есть несколько сеток, я читаю каждую из них с помощью 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])

Могу я добавить ярлык для каждой сетки? или добавить легенду?

1 Ответ

1 голос
/ 29 июля 2020

Да, это, естественно, можно сделать, и вы уже знаете ключевые слова, которые нужно использовать: 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()             

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

As you can see the strings passed as the label keyword argument of add_mesh turn into labels in a legend which you can enable with the add_legend() call. For customization options of the legend см. Документацию .

...