如何在 matplotlib 中使用 xy 数据设置 quiverkey 长度缩放?

Max*_*Max 5 python matplotlib

我正在尝试设置quiverkey与数据的特定箭头长度相匹配的绝对箭头长度quiver。有人可以告诉我这个quiverkey论点是如何U运作的,或者至少如何根据我的需要来扩展它吗?

背景

Python版本:3.6.5

matplotlib 版本:3.0.0

最小的例子

我稍微修改了示例:https://matplotlib.org/gallery/images_contours_and_fields/quiver_simple_demo.html#sphx-glr-gallery-images-contours-and-fields-quiver-simple-demo-py

import matplotlib.pyplot as plt
import numpy as np

X = np.arange(-10, 11, 2)
Y = np.arange(-10, 11, 2)
U, V = np.meshgrid(X, Y)

# calculate length of each arrow
data_arrow_length = np.abs(np.sqrt(np.square(U[:]) + np.square(U[:])))

# set displayed arrow length for longest arrow
displayed_arrow_length = 2

# calculate scale factor for quiver
scale_factor = np.max(data_arrow_length)/displayed_arrow_length

# mysterious arrow length for quiverkey
quiverkey_length = 200

fig, ax = plt.subplots()
q = ax.quiver(X, Y, U, V, pivot='middle',
              units='xy', width=0.1,
              scale=scale_factor, scale_units='xy')
ax.quiverkey(q, X=0.3, Y=1.1, U=quiverkey_length,
             label='Quiver key, length = 10', labelpos='E')

plt.show()
Run Code Online (Sandbox Code Playgroud)

这样我就可以控制quiver使用显示的最大箭头长度displayed_arrow_length。在此示例中,最大值data_arrow_length约为。14 并根据 xy 数据显示箭头长度为 2。

问题

如果我运行上面的示例,我会得到:

小地块

但是,如果我最大化图形窗口,我会得到:

大地块

箭头quiverkey长度不随我的quiver箭头缩放,我必须使用随机的高数字才能quiverkey_length完全显示。

问题

我想将quiverkey箭头长度设置为显示的特定值quiver,例如 10。但是,它似乎根本不随数据缩放。我怎样才能实现这个目标?

Max*_*Max 1

看来这是 matplotlib 中的一个错误,现已修复。

相关github问题