首页 > 解决方案 > 如何在 matplotlib 等高线图中添加一个点?

问题描述

我想在二维相空间中绘制一个常微分方程组的相图,并使用streamplotmatplotlib的功能来实现它。我想在图中标记一些点(固定点),但我不知道如何在同一张图上做,因为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()

标签: pythonmatplotlibplot

解决方案


推荐阅读