如何制作动画



帮助!我正试图制作一个函数,为微分方程的解设置动画,但它没有显示任何动画。有什么问题吗?

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
from matplotlib.animation import FuncAnimation
def animation(res, cap, l, i, fem):
neper_frec = float(res / l)
nat_frec = float(1/(cap*1)
initial_charge = float(cap*fem)
interval = np.linspace(0, 10, 600)
def ode(y, t):
charge, current = y
dydt = [current, -neper_frec*current - nat_frec*charge]
return dydt
y0 = [initial_charge, i]
sol = odeint(EDO, y0, interval)
fig, ax = plt.subplots()
ax.set(xlim=(0, 10), ylim=(-initial_charge, initial_charge))
line, = ax.plot([], [])
y = sol[:, 0]
def animate(i):
line.set_data(interval[:i], y[:i])
return line,
anim = FuncAnimation(fig, animate, frames = len(interval) + 1, interval = 20, blit = True)
plt.show()
#animacion(1.4, 1/600, 1.7, 0.5, 8)
  1. 取消注释#animacion(1.4, 1/600, 1.7, 0.5, 8)
  2. 将拼写更正为animation(1.4, 1/600, 1.7, 0.5, 8)
  3. 更正第行中的打字错误EDOode
sol = odeint(ode, y0, interval)

那么动画效果很好!

最新更新