如何在Matplotlib中將引數傳遞給animation.FuncAnimation()?
要在Python的Matplotlib中為等值線圖向animation.FuncAnimation()傳遞引數,我們可以執行以下步驟 -
- 建立一個10☓10維度的隨機數。
- 建立一個數字和一系列子圖,使用subplots()方法。
- 使用 FuncAnimation()類反覆呼叫函式*func*來製作動畫
- 要在函式中更新contour值,我們可以定義一個方法animate(),該方法可以用在FuncAnimation()類中。
- 使用show()方法顯示數字。
示例
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.randn(800).reshape(10, 10, 8) fig, ax = plt.subplots() def animate(i): ax.clear() ax.contourf(data[:, :, i]) ani = animation.FuncAnimation(fig, animate, 5, interval=50, blit=False) plt.show()
輸出

廣告
資料結構
計算機網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言
C++
C#
MongoDB
MySQL
Javascript
PHP