python - 如何在 matplotlib 等高线图中添加一个点?
问题描述
我想在二维相空间中绘制一个常微分方程组的相图,并使用streamplot
matplotlib的功能来实现它。我想在图中标记一些点(固定点),但我不知道如何在同一张图上做,因为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()
解决方案
推荐阅读
- excel - 如何在excel中的单个堆叠水平条形图上绘制一系列起点和终点
- c++ - 如何实现线程列表
- reactjs - Mobx 和反应。不支持实验语法
- angular - 等效于 Angular 中 C# 的简单“for”(使用索引迭代)
- python - 在嵌套列表python中查找所有可能的插入组合
- jquery - Ajax 成功刷新(如阴影)中的 Bootstrap 模态弹出窗口比消失 MVC
- reactjs - React js Axios 调用
- java - Android Studio:从海量数据中自动完成 EditText 输入
- mars-simulator - 火星模拟器数字实验室模拟中键盘的使用
- angular - 使用切片管道后如何连接字符串