如何在matplotlib等高线图中添加点?

时间:2018-10-15 17:53:58

标签: python matplotlib plot

我想在2D相空间中绘制一个常微分方程组的相图,并使用matplotlib的streamplot函数来实现它。而且我想在图中标记一些点(固定点),但是我不知道如何在同一张图上这样做,因为使用scatter仅在另一张图上绘制点。我该怎么做?以下是我目前拥有的:

import numpy as np
import matplotlib.pyplot as plt

"""
The system of ODE is given by:
dx/dt = alpha*(1-x)*x - c*x*y
dy/dt = -b*y + d*x*y
"""

# Set the parameters
alpha, b, c, d = 4, 3, 2, 1

# The fixed points
fp = [(0, 0), (1,0), (b/d, alpha/c*(1-b/d))]

# The phase portrait lies in {(x,y)|-l<x<l, -l<y<l} with n arrows in each dimension
l, n = 2, 41

# The 'velocity' of a point in phase space = (dx/dt, dy/dt)
def velocity(x, y):
    return alpha*(1-x)*x - c*x*y, -b*y + d*x*y

# Mesh the grids in x-y space
x, y = np.linspace(-l, l, n), np.linspace(-1, 1, n)
X, Y = np.meshgrid(x, y)
U, V = velocity(X, Y)
plt.figure()
plt.streamplot(X, Y, U, V)
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()

0 个答案:

没有答案