Python无箭头quiver图

3

我想制作一个无箭头的quiver图。我还想要边框,以使箭头从背景色的图中突出。这是我尝试生成此类绘图的主要代码部分:

plt.quiver(phia[sl1,sl2], R0a[sl1,sl2],u,v, color='white', headlength=0, headwidth = 1, pivot = 'middle', scale = scale, width=width, linewidth = 0.5)

如果这个问题很重要,那么图表将在极坐标轴上。对于大多数线条来说,这种方式都有效,但对于那些非常短的线条则不行。在这些情况下,线条之后会产生一些来自边界的人工尾巴。我生成的其中一个图表最受此影响,如下所示:

Quiver plot with artifacts at the end of lines

任何解决这个问题的方法或绕过它的建议都将不胜感激!谢谢!
1个回答

5
指定箭头的headaxislength参数为零即可解决问题:
import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0, 2*np.pi, 16)
r = np.linspace(0, 1, 6)
x = np.cos(theta)[:,np.newaxis]*r
y = np.sin(theta)[:,np.newaxis]*r

quiveropts = dict(color='white', headlength=0, pivot='middle', scale=3, 
    linewidth=.5, units='xy', width=.05, headwidth=1) # common options
f, (ax1, ax2) = plt.subplots(1,2, sharex=True, sharey=True)
ax1.quiver(x,y, -y, x, headaxislength=4.5, **quiveropts) # the default
ax2.quiver(x,y, -y, x, headaxislength=0, **quiveropts)

上面的代码将生成以下箭头无头的 quiverplot。 quiverplot without arrows

1
不是这种情况下的相关内容,但当您进行3D箭头图时,需要选项arrow_length_ratio=0 - zwep

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接