注釈
完全なサンプルコードをダウンロードしたり、Binderを使ってブラウザでこのサンプルを実行するには、 最後に進んでください 。
グリフ(矢印)によるベクトルの表示#
データセット内のベクトルを使用して,記号/ジオメトリオブジェクトを印刷したり方向を設定します.
import numpy as np
import pyvista as pv
from pyvista import examples
法線のあるデータセット例
mesh = examples.load_random_hills()
グリフィイングは pyvista.DataSetFilters.glyph()
フィルターを介して行うことができる
help(mesh.glyph)
入力データセットのすべてのノードにグリフが必要ない場合があります.この場合,マージ許容値を使用して,入力データセットのサブセットのグリフを作成することを選択できます.ここでは,5パーセントのマージ許容値を指定します.これは,バウンディングボックスの長さの5パーセントに相当します.
グリフフィルタを使用して矢印のサブセットを作成する
arrows = ...
p = pv.Plotter()
p.add_mesh(arrows, color="black")
p.add_mesh(mesh, scalars="Elevation", cmap="terrain", smooth_shading=True)
p.show()
一般的な方法は,メッシュオブジェクトに直接ベクトルをロードして,グリフを生成するために pyvista.DataSet.arrows
プロパティにアクセスする方法です.
# add and scale
sphere["vectors"] = vectors * 0.3
sphere.set_active_vectors("vectors")
# plot just the arrows
sphere.arrows.plot()
矢印と球体をプロットします.
p = pv.Plotter()
p.add_mesh(sphere.arrows, lighting=False, scalar_bar_args={"title": "Vector Magnitude"})
p.add_mesh(sphere, color="grey", ambient=0.6, opacity=0.5, show_edges=False)
p.show()