Matplotlib动画在IPython Notebook中无法工作?

Matplotlib动画在IPython Notebook中无法工作?

要在matplotlib中制作动画,可以按照以下步骤进行:

  • 设置图形大小并调整子图之间和周围的填充。

  • 创建一个形状为10X10维度的随机数据。

  • 使用 subplots() 方法创建一个图形和一组子图。

  • 使用FuncAnimation()类通过重复调用一个函数 func 来实现动画效果。

  • 要在一个函数中更新等高线的值,可以定义一个在FuncAnimation()类中可用的方法animate。

  • 使用 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()
Python

输出

Matplotlib动画在IPython Notebook中无法工作?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册