matplotlib中相等的箭头

2024-10-02 18:18:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用matplotlib绘制箭头,这样不管实际箭头的大小,每个箭头的大小都是相等的。在

示例:

箭头是用matplotlib.pyplot.Arrow():

# p is the point of origin, pdiff the direction        
arr = plt.Arrow(p[0], p[1], pdiff[0], pdiff[1], fc=color, width=0.4)
plt.gca().add_patch(arr)

Tags: thecomhttp示例pngmatplotlib绘制plt
1条回答
网友
1楼 · 发布于 2024-10-02 18:18:19

您在pylab.arrow(或FancyArrow)之后,可以指定head_width和{},这样它们与箭头的大小无关。下面是一个例子:

import math
import pylab

pylab.plot(range(11), range(11))

opt = {'head_width': 0.4, 'head_length': 0.4, 'width': 0.2,
        'length_includes_head': True}
for i in xrange(1, 360, 20):
    x = math.radians(i)*math.cos(math.radians(i))
    y = math.radians(i)*math.sin(math.radians(i))

    # Here is your method.    
    arr = pylab.Arrow(4, 6, x, y, fc='r', alpha=0.3)
    pylab.gca().add_patch(arr)

    # Here is the proposed method.
    pylab.arrow(4, 6, x, y, alpha=0.8, **opt)

pylab.show()

产生:

enter image description here

相关问题 更多 >