|
実行結果の動画です。ループ再生します。
Python 3.11.6 (matplotlib 3.7.1) と Python 3.12.0 (matplotlib 3.8.1) 共に、下記のような警告があり、無限ループです。
無限ループを、回避するため提案の通り save_count=MAX_FRAMES を追加し、長さ 60 秒の動画を作成しました。
E:\______\random_data.py:28: UserWarning:
frames= which we can infer
the length of, did not pass an explicit *save_count* and passed
cache_frame_data=True.
To avoid a possibly unbounded cache, frame data caching has been
disabled. To suppress this warning either pass `cache_frame_data=False`
or `save_count=MAX_FRAMES`.
ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
下記のように、save_count=900 を追加しました。
"""
===========
Random data
===========
An animation of random data.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)
def update(data):
line.set_ydata(data)
return line,
def data_gen():
while True:
yield np.random.rand(10)
ani = animation.FuncAnimation(fig, update, data_gen,
interval=100, save_count=900)
ani.save("random_data_2.mp4", fps=15)
plt.show()
実行結果の動画(random_data_2.mp4)です。
|