python matplotlib quiver

2023-05-16

matplotlib中的 quiver方法可用于绘制箭头(向量),下面介绍二维和三维中的使用方法

二维箭头向量绘制

一般参数如下

quiver(X, Y, U, V, **kw)

参数的含义如下图所示,其中XY决定箭头尾部的位置,UV决定箭头的方向,可以理解为以箭头尾部为起点,沿X和Y轴的分量。
在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 40)
y = x ** 2 * np.exp(-x)
u = np.array([x[i + 1] - x[i] for i in range(len(x) - 1)])
v = np.array([y[i + 1] - y[i] for i in range(len(x) - 1)])
x = x[:len(u)]  # 使得维数和u,v一致
y = y[:len(v)]
c = np.random.randn(len(u))  # arrow颜色
plt.figure()
plt.quiver(x, y, u, v, c, angles='xy', scale_units='xy', scale=1)
plt.show()

在这里插入图片描述

三维箭头向量绘制

三维和二维类似,只不过多了一个维度,参数的意义是一样的

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 绘制点
num_points = 20
pts = np.random.rand(num_points, 3)
ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2], c='b', s=3, linewidth=0, alpha=1, marker="o")

# 绘制箭头
direction = np.random.rand(num_points, 3)
ax.quiver(pts[:, 0], pts[:, 1], pts[:, 2],
          direction[:, 0], direction[:, 1], direction[:, 2],
          length=0.05, normalize=True, color='r')
plt.show()

在这里插入图片描述

参考

  • matplotlib quiver箭图绘制
  • python matplotlib quiver——画箭头、风场
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python matplotlib quiver 的相关文章

随机推荐

  • Linux配置ssh

    服务器主机安装ssh sudo apt get install openssh server xff0c 客户端使用putty等支持ssh的软件登录即可 xff0c 记住服务器的ip和密码
  • pytorch计算模型参数量

    total span class token operator 61 span span class token builtin sum span span class token punctuation span span class t
  • 【字符串】把字符串转换成整数

    题目描述 将一个字符串转换成一个整数 xff0c 要求不能使用字符串转换整数的库函数 数值为0或者字符串不是一个合法的数值则返回0 输入描述 输入一个字符串 包括数字字母符号 可以为空 返回值描述 如果是合法的数值表达则返回该数字 xff0
  • 【树】二叉树的镜像

    题目描述 操作给定的二叉树 xff0c 将其变换为源二叉树的镜像 思路很简单 xff0c 只需要递归遍历树 xff0c 然后将每个节点的左右子树调换即可 span class token keyword import span java s
  • 【树】树的子结构

    来自剑指offer 这题有点难度 xff0c 解题思想是 xff1a 若B是A的子树 xff0c 则子树的根节点可能为树A中的任意一个节点 xff0c 因此只需要遍历树A的每个节点 xff0c 判断以这个节点为根节点的树是否包含子树B xf
  • Docker 网络

    1 简介 容器网络实质上是由 Docker 为应用程序所创造的虚拟环境的一部分 xff0c 它能让应用从宿主机操作系统的网络环境中独立出来 xff0c 形成容器自有的网络设备 IP 协议栈 端口套接字 IP 路由表 防火墙等与网络相关的模块
  • Ubuntu 20安装Nvidia驱动 + cuda10.1 + Anaconda + pytorch 1.5

    安装Nvidia驱动 输入命令 ubuntu drivers devices查看显卡推荐的驱动选择recommend的版本进行安装 xff0c 例如我的是460 sudo apt install nvidia driver 460 安装完成
  • VScode ssh远程服务器解决试图写入的管道不存在

    解决方案 xff0c 在C盘用户目录下找到 ssh文件 xff0c 删除known hosts文件或打开known hosts删除对应的ip
  • S3DIS场景点云数据集

    S3DIS是常用的室内场景分割数据集 xff0c 包含6个Area xff0c 常用的数据格式如下 xff1a Stanford3dDataset v1 2 Aligned Version xff0c 百度网盘下载 xff0c 提取码0ac
  • jupyter远程连接服务器

    服务器终端输入命令 jupyter notebook no browser port 61 8889 本地终端输入命令 ssh N f L localhost 8888 localhost 8889 username 64 ip usern
  • win10远程Linux桌面

    在Linux服务器安装xrdp xff1a sudo apt install xrdp win10远程 xff0c win 43 R xff0c 输入mstsc xff0c 输入linux服务器ip和账户 具体参考 https www ma
  • python控制输出精度

    a span class token operator 61 span span class token number 3 1456 span b span class token operator 61 span span class t
  • 多分类混淆矩阵的理解

    借用其它博客的一张例子示意图 xff0c 该图为一个三分类问题的混淆矩阵 xff0c 对角线的值表示分类器对该类别预测正确的个数 xff0c 每一列纵轴表示这个类别真实的样本数 xff0c 例如从第一列可以得知猫一共有10 43 3 43
  • ERROR: Could not find a version that satisfies the requirement dateutil

    安装dateutil出错 xff0c 提示 ERROR Could not find a version that satisfies the requirement dateutil 解决办法 xff1a pip install pyth
  • RTX3090 + cuda 11.1 + torch1.9.0 安装 MinkowskiEngine

    创建conda环境 conda create n mink span class token assign left variable python span span class token operator 61 span span c
  • pytorch更新tensor中指定index位置的值scatter_add_

    使用scatter add 更新tensor张量中指定index位置的值 例子 span class token keyword import span torch a span class token operator 61 span t
  • Docker 私有仓库

    1 Registry 官方私有仓库 xff0c 优点 xff1a 简单 xff1b 缺点 xff1a 部署无法进行复杂的管理操作 1 1 镜像 docker pull registry 2 7 1 docker pull joxit doc
  • pytorch one-hot编码

    使用scatter 将标签转换为one hot span class token keyword import span torch num class span class token operator 61 span span clas
  • python安装meshplot

    用conda或者pip直接安装如果出问题 xff0c 可以考虑使用以下方法 xff0c 从代码仓库中安装 下载代码库 span class token function git span clone https github com sko
  • python matplotlib quiver

    matplotlib中的 quiver方法可用于绘制箭头 xff08 向量 xff09 xff0c 下面介绍二维和三维中的使用方法 二维箭头向量绘制 一般参数如下 quiver span class token punctuation sp