1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

時系列データのプロットをPythonでアニメーション表示

Posted at

X-Yプロットをアニメーション表示するサンプル

XY_plot_anim.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

# サンプル時系列加速度データを生成(ここに実際のデータを使用)
t = np.linspace(0, 10, 100)
acceleration = np.sin(2 * np.pi * t)  # 加速度データの例

# フィギュアとプロットの作成
fig, ax = plt.subplots()
ax.set_xlim(0, 10)
ax.set_ylim(-1.5, 1.5)
line, = ax.plot([], [], lw=2)

# 初期化関数
def init():
    line.set_data([], [])
    return (line,)

# アニメーション関数
def animate(i):
    x = t[:i]
    y = acceleration[:i]
    line.set_data(x, y)
    return (line,)

# アニメーションの設定
ani = animation.FuncAnimation(fig, animate, init_func=init, frames=len(t), interval=100, blit=True)

# GIFとして保存
ani.save("animation.gif", writer='pillow', fps=10)

# アニメーションの表示
plt.show()

animation.gif

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?