線ウィジェット

線ウィジェット#

行ウィジェットは, pyvista.WidgetHelper.add_line_widget() および pyvista.WidgetHelper.clear_line_widgets() メソッドによって,それぞれ有効および無効にすることができます.残念ながら,PyVistaにはこのウィジェットを利用するヘルパー・メソッドがないため,カスタムのコールバック・メソッドを渡す必要があります.

特に面白い例は,行ウィジェットを使って pyvista.DataSetFilters.streamlines() フィルタのソースを作成することです. add_meshname 引数を使用していることに再度注意してください.

import numpy as np

import pyvista as pv
from pyvista import examples

pv.set_plot_theme('document')

mesh = examples.download_kitchen()
furniture = examples.download_kitchen(split=True)

arr = np.linalg.norm(mesh['velocity'], axis=1)
clim = [arr.min(), arr.max()]
p = pv.Plotter()
p.add_mesh(furniture, name='furniture', color=True)
p.add_mesh(mesh.outline(), color='black')
p.add_axes()


def simulate(pointa, pointb):
    streamlines = mesh.streamlines(
        n_points=10,
        max_steps=100,
        pointa=pointa,
        pointb=pointb,
        integration_direction='forward',
    )
    p.add_mesh(streamlines, name='streamlines', line_width=5, render_lines_as_tubes=True, clim=clim)


p.add_line_widget(callback=simulate, use_vertices=True)
p.show()
line widget

以下はユーザ対話型のスクリーンショットです

../../_images/line-widget-streamlines.gif

%% .. tags:: widgets

Total running time of the script: (0 minutes 0.592 seconds)

Sphinx-Galleryによるギャラリー