Home>

Please write your question in detail here.
http://dsng.hatenablog.com/entry/2013/02/06/150713
Trying to animate the Lotka Volterra equation, see https://omedstu.jimdo.com/2018/06/21/fitzhugh-nagumo model in animation/
I tried remodeling the code written on the above site,
Only the frame of the figure appears and no animation is displayed

Because I am a beginner in programming and scientific calculation, I have no idea where to fix it.
Thank you.

Error message
Animation is not displayed
Only the frame of the figure comes out
Copy and paste is where do not know what went wrong because it is written in the center
Applicable source code
% matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import scipy.integrate as integrate
from matplotlib.animation import FuncAnimation

a = 2. # Prey birth rate
b = .1 # prey prey rate
c = 1.5 # predator mortality
d = 0.75 # Predator increase rate
def lotka_volterra (state, t):
    prey, pred = state
    dot_prey = prey * (a-b * pred)
    dot_pred = pred * (-c + d * b * prey)
    return dot_prey, dot_pred
prey0 = 10
prey0 = 5
fig = plt.figure ()
t = np.arange (0.0, 10, 0.01)
len_t = len (t)
dt = 5
def update (i):
    global y, y0
    if i == 0:
        y0 = [prey0, pred0]
    plt.cla ()
    y = integrate.odeint (lotka_volterra, y0, t)
    y0 = (y [dt, 0], y [dt, 1])
    prey = y [:, 0]
    pred = y [:, 1]
    plt.plot (t, prey, label = "prey: prey", color = "# ff7f0e")
    plt.plot (t, pred, label = "pred: predator", color = "# 1f77b4")
    plt.plot (t [len_t-1], prey [len_t-1], 'o--', color = "# ff7f0e")
    plt.plot (t [len_t-1], pred [len_t-1], 'o--', color = "# 1f77b4")
    plt.grid ()
    plt.legend (bbox_to_anchor = (0, 1),
               loc = 'upper left',
               borderaxespad = 0)
ani = animation.FuncAnimation (fig, update, interval = 100,
                              frames = 300)
plt.show ()

Each point that is different from the above site and check each point, erase or write

Supplemental information (FW/tool version etc.)

http://dsng.hatenablog.com/entry/2013/02/06/150713
https://omedstu.jimdo.com/2018/06/21/ See the fitzhugh-nagumo model in animation/

  • Answer # 1

    prey0 = 10
    prey0 = 5

    The variable here was wrong,
    pred0 = 5

    I ’m sorry,

Related articles