LoginSignup
9
14

More than 5 years have passed since last update.

matplotlibで画像を連続的に表示する方法メモ

Last updated at Posted at 2017-03-19

この記事は「この記事は最終更新日から1年以上が経過しています。」を経験しています。

matplotlib.animationを使って連続的に生成される画像を表示したい。次のように画像生成してimshowする関数を作ればこれができる。
途中plt.clf()をしているのは、ステップを重ねるごとに重くなっているように思えたので、毎度クリアしてみたというもの。

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

N = 50

fig, ax = plt.subplots()

def update(i):
  a = np.uint8(np.random.uniform(0, 255, [N, N, 3]))
  a[i:, i:] = 0.
  plt.clf()
  plt.imshow(a)
hoge = animation.FuncAnimation(fig, update, np.arange(1,  N), interval=25)  # 代入しないと消される
plt.show()

以上。

9
14
2

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
9
14