注
最後まで移動して完全なサンプルコードをダウンロードするか、JupyterLite または Binder を介してブラウザでこのサンプルを実行します。
Matplotlib のアニメーションのサポート#
Matplotlib のアニメーションを表示します。うまく埋め込まれるとよいのですが。
アニメーションのサポートを有効にするには、sphinx ギャラリーの設定で'matplotlib_animations'
をTrue
に設定する必要があります。
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
# Adapted from
# https://matplotlib.org/gallery/animation/basic_example.html
def _update_line(num):
line.set_data(data[..., :num])
return (line,)
fig, ax = plt.subplots()
data = np.random.RandomState(0).rand(2, 25)
(line,) = ax.plot([], [], "r-")
ax.set(xlim=(0, 1), ylim=(0, 1))
ani = animation.FuncAnimation(fig, _update_line, 25, interval=100, blit=True)
スクリプトの合計実行時間: (0 分 2.310 秒)
推定メモリ使用量: 176 MB