如何使用Matplotlib使箭头指向与箭头相同的方向

3

我正在使用这段代码

import matplotlib.pyplot as plt

plt.figure(1)
plt.axis(xmin=0, xmax=60, ymin=0, ymax=0.25)
plt.arrow(30, 0.01, 10, 0.1, head_width=0.05, head_length=1, length_includes_head=True)
plt.savefig('arrow.png')

我希望得到一个与箭头线条方向相同的箭头,但实际上它并没有指向同一方向。

enter image description here

这个问题有什么解决方法(为什么会发生这种情况)?

1个回答

3

部分原因已经在这里简要提到了:此处

注释

生成的箭头受轴的长宽比和限制的影响。这可能会产生一个箭头,其头部与其干不成正方形。要创建一个头部与干成正方形的箭头,请使用annotate()。

你介意做这个吗?

import matplotlib.pyplot as plt

plt.figure(1)
plt.axis(xmin=0, xmax=60, ymin=0, ymax=0.25)
# plt.arrow(30, 0.01, 10, 0.1, head_width=0.05, head_length=1, length_includes_head=True)
plt.annotate("", xy=(40, 0.11), xytext=(30, 0.01), arrowprops=dict(headwidth=10, headlength=10, width=0.1))
plt.savefig('arrow.png')

enter image description here


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