0

This code allows me to plot the the mutualistic relationship of two species. As the code gives, the graph is logistical. Given this, I should be able to see how its phase portrait looks like. My question is: how and where should I start if I need to show its phase plane/portrait using scipy?

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import pylab as p

# parameters
r1 = 1.0
r2 = 0.5
e1 = 1
e2 = 0.75
a12 = 0.25
a21 = 0.25

# initial population
N10 = 1
N20 = 1

# store initial values in an array
X0 = [N10, N20]

# model/equation
def mutualism(X,t):
  N1, N2 = X
  dX = np.zeros(2) # initialize dX as array containing three zeroes
  dX[0] = N1 * (r1 - (e1 * N1) + (a12 * N2)) # equation for dN10dt
  dX[1] = N2 * (r2 - (e2 * N2) + (a21 * N1)) # equation for dN20dt
  return dX

# set time length
t = np.linspace(0, 100,100*10)

# odeint returns an array containing values for each value of t
X = odeint(mutualism,X0,t)

N1 = X[:,0]; N2 = X[:,1]

#plot
f1 = p.figure()
p.plot(t, N1, 'r-', label='Species 1')
p.plot(t, N2  , 'b-', label='Species 2')
p.grid()
p.legend(loc='best')
p.xlabel('Time')
p.ylabel('Population')
p.title('Mutualism')

So far I've tried using matplotlib in generating the phase portrait but to no avail, it did not work.

thepajama
  • 55
  • 1
  • 9
  • You're going to need to be more specific about what exactly a phase portrait is. Do you mean just plotting `N1` against `N2`? – AJ Biffl Nov 15 '21 at 02:55
  • 1
    Use `streamplot`, for examples see the matplotlib documentation and https://stackoverflow.com/questions/58701195/plotting-phase-portraits-in-python-using-polar-coordinates/66052198#66052198, https://stackoverflow.com/questions/49807524/how-do-i-use-pylab-to-plot-a-phase-plane-for-pendulum-motion/49812476#49812476 – Lutz Lehmann Nov 15 '21 at 08:53

0 Answers0