アニメーション (gifplot)
gifplot() は多次元データから時系列アニメーションを作成します。plot() に次いで 2 番目によく使う機能です。
基本的な使い方
import emout
data = emout.Emout("output_dir")
# Jupyter Notebook でインライン表示(デフォルト: action='to_html')
data.phisp[:, 100, :, :].gifplot()
スライス [:, 100, :, :] は z=100 での全タイムステップを選択し、xy 平面の時間変化アニメーションを生成します。
出力アクション
action パラメータでフレーム生成後の動作を制御します:
アクション |
説明 |
|---|---|
|
Jupyter インライン表示用の HTML を返す(デフォルト) |
|
matplotlib ウィンドウで表示 |
|
ファイルに保存( |
|
|
|
マルチパネルレイアウト用の |
# GIF として保存
data.phisp[:, 100, :, :].gifplot(action="save", filename="phisp.gif")
# matplotlib ウィンドウで表示
data.phisp[:, 100, :, :].gifplot(action="show")
主なオプション
パラメータ |
型 |
説明 |
デフォルト |
|---|---|---|---|
|
|
出力モード(上表参照) |
|
|
|
|
|
|
|
アニメーション軸 |
|
|
|
フレーム間隔 [ミリ秒] |
|
|
|
ループ再生 |
|
|
|
SI 単位ラベルを使用 |
|
|
|
カラーバーの最小値 |
自動 |
|
|
カラーバーの最大値 |
自動 |
|
|
|
|
|
|
プロットモード( |
自動 |
複数パネルアニメーション
複数データソースをグリッドレイアウトで 1 つのアニメーションにまとめます:
# ステップ1: フレームアップデータを作成
updater0 = data.phisp[:, 100, :, :].gifplot(action="frames", mode="cmap")
updater1 = data.phisp[:, 100, :, :].build_frame_updater(mode="cont")
updater2 = data.nd1p[:, 100, :, :].build_frame_updater(
mode="cmap", vmin=1e-3, vmax=20, norm="log"
)
updater3 = data.nd2p[:, 100, :, :].build_frame_updater(
mode="cmap", vmin=1e-3, vmax=20, norm="log"
)
updater4 = data.j2xy[:, 100, :, :].build_frame_updater(mode="stream")
# ステップ2: レイアウトを3重リストで定義 [行][列][重ね合わせ]
layout = [
[
[updater0, updater1], # 行0, 列0: カラーマップ + 等高線重ね合わせ
[updater2], # 行0, 列1: 密度(対数スケール)
[updater3, updater4], # 行0, 列2: 密度 + ストリームライン重ね合わせ
]
]
# ステップ3: Animator を作成して表示
animator = updater0.to_animator(layout=layout)
animator.plot(action="to_html")
レイアウト構造
レイアウトは 3 重のネストされたリスト です:
レベル 1(外側): 行
レベル 2: 行内の列
レベル 3(内側): 同じサブプロットに重ね描きする updater
最内リスト内の各 updater は同じ Axes に描画されるため、異なる可視化モードの重ね合わせ(例: カラーマップ + 等高線、密度 + ストリームライン)が可能です。
build_frame_updater と gifplot(action='frames') の違い
どちらも FrameUpdater オブジェクトを生成します。違いは:
gifplot(action='frames')は簡易ショートカットbuild_frame_updater()はmode,vmin,vmax等を明示的に制御可能
パネルごとにカスタマイズが必要な場合は build_frame_updater() を使います。