如何画分岔图

微分方程组 ODEs

Toggle switch 模型:
\begin{aligned}
\newcommand{\dd}{\mathrm{d}}
\frac{\dd X}{\dd t} & = \frac{a_1}{1 + Y^n} - d_1 X + b_1 S,\\
\frac{\dd Y}{\dd t} & = \frac{a_2}{1 + X^n} - d_2 Y + b_2.
\end{aligned}

代码

#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt

datafile = 'fig3b.dat'
data = np.loadtxt(datafile)
# solid
a1s = [i[0] for i in data if i[3] == 1]
m1s = [i[1] for i in data if i[3] == 1]
# dashed
a1d = [i[0] for i in data if i[3] == 2]
m1d = [i[1] for i in data if i[3] == 2]
# dotted
a1dd = [i[0] for i in data if i[3] == 3]
# dotted upper
m1u = [i[1] for i in data if i[3] == 3]
# dotted lower
m1l = [i[2] for i in data if i[3] == 3]
# HB point
HBx = [i[0] for i in data if i[3] == 4]
HBy = [i[1] for i in data if i[3] == 4]

plt.figure(figsize=(8, 6), dpi=80)
plt.xlim(0, 120)
plt.ylim(0, 50)
plt.xticks([0, 40, 80, 120])
plt.xlabel(r'$\alpha_1$')
plt.ylabel(r'$M_1$')

plt.plot(a1s, m1s, 'k-', lw=2)
plt.plot(a1d, m1d, 'k--', lw=2)
plt.plot(a1dd[::3], m1u[::3], 'ko', ms=1.5)
plt.plot(a1dd[::3], m1l[::3], 'ko', ms=1.5)
plt.plot(HBx, HBy, 'ro')
plt.annotate('HB', 
             xy=(HBx[0], HBy[0] + 1.5), 
             xytext=(HBx[0] + 2, HBy[0] + 18),
             arrowprops=dict(arrowstyle="->",
             lw=1.5, fc='k')
)
plt.savefig('fig3b.pdf')
plt.show()

fig3b

2014-04-24 11:4065xppautPythonNumpyMatplotlib
comments powered by Disqus