先进的 quiver 和 quiverkey 功能#

演示了一些更高级的选项quiver。有关简单示例,请参阅Quiver Simple Demo

注意:绘图自动缩放不考虑箭头,因此边界上的箭头可能会超出图片。这不是一个容易以完全通用的方式解决的问题。推荐的解决方法是在这种情况下手动设置轴限制。

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)
fig1, ax1 = plt.subplots()
ax1.set_title('Arrows scale with plot width, not view')
Q = ax1.quiver(X, Y, U, V, units='width')
qk = ax1.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E',
                   coordinates='figure')
箭头随绘图宽度缩放,而不是视图
fig2, ax2 = plt.subplots()
ax2.set_title("pivot='mid'; every third arrow; units='inches'")
Q = ax2.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
               pivot='mid', units='inches')
qk = ax2.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
                   coordinates='figure')
ax2.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5)
枢轴='中';  每三个箭头; 单位='英寸'
<matplotlib.collections.PathCollection object at 0x7f2cfad10ac0>
fig3, ax3 = plt.subplots()
ax3.set_title("pivot='tip'; scales with x view")
M = np.hypot(U, V)
Q = ax3.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022,
               scale=1 / 0.15)
qk = ax3.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
                   coordinates='figure')
ax3.scatter(X, Y, color='0.5', s=1)

plt.show()
枢轴='提示';  带有 x 视图的刻度

参考

此示例中显示了以下函数、方法、类和模块的使用:

脚本总运行时间:(0分1.864秒)

由 Sphinx-Gallery 生成的画廊