如何在Python中使用matplotlib.animate来对等值线图进行动画处理?
若要使用matplotlib 在Python中对等值线图进行动画处理,我们可以采取以下步骤-
- 创建形状为10☓10维度的随机数据。
- 使用subplots()方法创建一幅图和一组子图。
- 使用FuncAnimation()类反复调用函数*func*,制作动画。
- 若要更新函数中的等值线值,我们可以定义一个方法animate,该方法可用于FuncAnimation()类。
- 若要显示图形,请使用show()方法。
示例
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation plt.rcParams["figure.figsize"] = [7.00, 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