无论matplotlib中箭头的角度如何,都使箭头形状对称

dyl*_*nan 9 python matplotlib

以下代码产生下图。箭头的形状取决于箭头的角度。如何使所有箭头都具有相同的对称形状?我特别要求 Python 3,但欢迎使用通用解决方案。

import matplotlib.pyplot as plt
plt.arrow(0, 0, .5, .5, head_width = .1)
plt.arrow(0, 0, .2, .5, head_width = .1)
plt.arrow(0, 0,  0, .5, head_width = .1)
plt.axis((-1, 1, -1 ,1))
plt.show()
Run Code Online (Sandbox Code Playgroud)

箭头演示

Imp*_*est 9

这是不可能的plt.arrow。我想plt.arrow仍然存在的原因纯粹是为了向后兼容。箭头更好地由matplotlib.patches.FancyArrowPatch. FancyArrowPatch在你的情节中获得这样的最简单方法是通过plt.annotate.

import matplotlib.pyplot as plt

prop = dict(arrowstyle="-|>,head_width=0.4,head_length=0.8",
            shrinkA=0,shrinkB=0)

plt.annotate("", xy=(.5,.5), xytext=(0,0), arrowprops=prop)
plt.annotate("", xy=(.2,.5), xytext=(0,0), arrowprops=prop)
plt.annotate("", xy=(.0,.5), xytext=(0,0), arrowprops=prop)

plt.axis((-1, 1, -1 ,1))
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Arrows 目前的文档不足,但仍有计划编写一些完整的教程或指南。