matplotlib.patches.FancyArrow使泰山变薄了

2024-04-24 01:45:30 发布

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

执行此代码时:

plt.figure(figsize=(3,3))
plt.xlim(-3, 3); plt.ylim(-3,3); 
plt.arrow(0,0, 2, 2, head_length=1.4, head_width=1.8, width=1.4,
   alpha=0.2, length_includes_head=True, fc='r')

我得到以下输出:

enter image description here

不过,我不想尾巴缩水。在我的另一台电脑上我没有这个问题。有人知道怎么解决吗?在

我的matplotlib版本是2.0.0。在


Tags: 代码alphatruepltwidthlengthhead尾巴
1条回答
网友
1楼 · 发布于 2024-04-24 01:45:30

这似乎是arrow中的某种bug。您可能希望有一个tail_width参数来设置箭头(或其尾部)的宽度。但这并不存在。在

作为解决方法,您可以使用FancyArrowPatch,您需要手动将其添加到轴上。FancyArrowPatch有一个参数arrowstyle,您可以为其提供一个参数字符串。在此字符串中,"tail_width"被正确识别。在

import matplotlib.pyplot as plt
import matplotlib.patches as patches

plt.figure(figsize=(3,3))
plt.xlim(-3, 3); plt.ylim(-3,3);

style="Simple,head_length=28,head_width=36,tail_width=20"
plt.gca().add_patch(
        patches.FancyArrowPatch((0,0), (2,2),arrowstyle=style,alpha=0.2,fc='r' ))

plt.show()

enter image description here

相关问题 更多 >