注釈
Go to the end をクリックすると完全なサンプルコードをダウンロードできます.
GIFムービーの作成#
アクティブなプロッタから動くgifを生成します.
注釈
特にスカラーバーでは,"jittery" な GIF を避けるために,lighting=False
を使って色空間のサイズを小さくしてください.
from __future__ import annotations
import numpy as np
import pyvista as pv
構造化グリッドの作成#
構造化されたグリッドを作成し,原点からのデカルト距離に基づいてZ位置をシフトする "波" を作ります.

GIFを生成する#
off_screen=True
パラメータを使用してGIFを生成します.
# Create a plotter object and set the scalars to the Z height
plotter = pv.Plotter(notebook=False, off_screen=True)
plotter.add_mesh(
grid,
scalars='Height',
lighting=False,
show_edges=True,
clim=[-1, 1],
)
# Open a gif
plotter.open_gif('wave.gif')
# Update Z and write a frame for each updated position
nframe = 15
for phase in np.linspace(0, 2 * np.pi, nframe + 1)[:nframe]:
z = np.sin(r + phase)
# Update values inplace
grid.points[:, -1] = z.ravel()
grid['Height'] = z.ravel()
# Write a frame. This triggers a render.
plotter.write_frame()
# Closes and finalizes movie
plotter.close()

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