Pythonによる簡易的なモードアニメーションの例
Sin波形の振幅が変化するアニメーションプロット
mode_anim.py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# モード形状データ(例)
x = np.linspace(0, 10, 100)
mode_shape = np.sin(x)
# アニメーション用データ生成
def update(frame):
line.set_ydata(mode_shape * np.sin(2 * np.pi * frame / 100))
return line,
# プロット設定
fig, ax = plt.subplots()
line, = ax.plot(x, mode_shape)
ax.set_ylim(-1.5, 1.5)
# アニメーション作成
ani = FuncAnimation(fig, update, frames=100, interval=50)
# GIFとして保存
ani.save("animation.gif", writer='pillow', fps=10)
# アニメーションの表示
plt.show()