0
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で時系列データを1秒ごとに追加表示するサンプルプログラム

Posted at

読み込んだデータを時系列表示する際に,逐次(1秒ごと)に追加(更新)してプロットするサンプルプログラム

出力プロット例

add_plotting.gif

コードブロック

add_plotting.py
import time
import random
import matplotlib.pyplot as plt
import matplotlib.animation as animation

# ランダムな時系列データを生成
data = [random.randint(0, 10) for _ in range(10)]

# FigureとAxesを作成
fig, ax = plt.subplots()
line, = ax.plot([], [])

# Axesの設定
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Value")

# アニメーションの更新関数
def update(frame):
    x = list(range(frame + 1))
    y = data[:frame + 1]
    line.set_data(x, y)
    return line,

# アニメーションの生成と表示
ani = animation.FuncAnimation(fig, update, frames=10, interval=1000, blit=True)
plt.show()
0
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
0
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?