博客
关于我
quiver绘制python语言
阅读量:794 次
发布时间:2023-03-02

本文共 1418 字,大约阅读时间需要 4 分钟。

Matplotlib Quiver 和 QuiverKey 功能示例

矩阵图表库 Matplotlib 中的 quiverquiverkey 功能可以用来绘制矢量字段图,并添加注释以显示数据的单位和方向。然而,这些功能在处理图像缩放时存在一个常见问题:箭头的缩放不考虑边缘的可视范围,可能导致边缘的箭头超出图像范围。解决这一问题的工作-around是手动调整坐标轴的范围。

以下是几个使用 quiverquiverkey 的示例:

示例一:箭头按图像宽度缩放

import matplotlib.pyplot as plt
import numpy as np
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
U = np.cos(X)
V = np.sin(Y)
plt.figure()
plt.title('Arrows scale with plot width, not view')
Q = plt.quiver(X, Y, U, V, units='width') # 箭头按图像宽度缩放
qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='figure') # 添加注释
plt.figure()
plt.title("pivot='mid'; every third arrow; units='inches'")
Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
pivot='mid', units='inches') # 箭头以每个第三个箭头为基准,单位为英寸
qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', coordinates='figure') # 添加注释
plt.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5) # 添加标记
plt.figure()
plt.title("pivot='tip'; scales with x view")
M = np.hypot(U, V)
Q = plt.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1 / 0.15) # 箭头以箭头头部为基准,按 x 轴缩放
qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', coordinates='figure') # 添加注释
plt.scatter(X, Y, color='k', s=5) # 添加标记

总结

通过上述示例可以看到,quiverquiverkey 函数提供了灵活的矢量图绘制工具。无论是按宽度、英寸还是 x 轴缩放,都可以通过设置不同的参数来实现。然而,手动调整坐标轴范围仍然是解决边缘箭头超出图像范围的有效方法。

转载地址:http://fetfk.baihongyu.com/

你可能感兴趣的文章
PHP生成器-动态生成内容的数组
查看>>
PHP的ip2long和long2ip升级函数
查看>>
PHP的json_encode函数应用到微信接口问题(include \uxxxx will create fail)
查看>>
PHP的readfile函数和file_get_contents函数错误: Unable to find the wrapper "https"
查看>>
php的web路径获取
查看>>
php的一些小笔记--字符串
查看>>
php的几种运行模式CLI、CGI、FastCGI、mod_php
查看>>
php的四大特性八大优势
查看>>
RabbitMQ
查看>>
PHP的威胁函数与PHP代码审计实战
查看>>
PHP的引用举例
查看>>
PHP相关代码
查看>>
RabbitMQ
查看>>
php知识点记录
查看>>
PHP知识笔记:CGI, FastCGI, PHP-CGI, PHP-FPM, Spawn-FCGI区别
查看>>
PHP第三方登录—OAuth2.0协议
查看>>
php筛选js,php如何多条件筛选js代码
查看>>
R730服务器做了raid的硬盘,插在R720上面可以用吗?
查看>>
PHP类数组式访问(ArrayAccess接口)
查看>>
PHP系列:浅谈PHP中isset()和empty() 函数的区别
查看>>