python - 如何使用 FancyArrowPatch 制作不同类型的箭头?
问题描述
FancyArrowPatch
我想在 matplotlib 中使用以下箭头:
产生上述情节的代码是(取自这里):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4,4))
v = [-0.2, 0, .2, .4, .6, .8, 1]
for i, overhang in enumerate(v):
ax.arrow(.1,overhang,.6,0, width=0.001, color="k",
head_width=0.1, head_length=0.15, overhang=overhang)
ax.set_yticks(v)
ax.set_xticks([])
ax.set_ylabel("overhang")
ax.set_ylim(-0.3,1.1)
plt.tight_layout()
plt.show()
上面的代码使用ax.arrow
. 我怎样才能实现这个FancyArrowPatch
?
解决方案
也许它有助于试验FancyArrowPatch
, ArrowStyle
:
from matplotlib.patches import FancyArrowPatch, ArrowStyle
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
style = ArrowStyle('Fancy', head_length=1, head_width=1.5, tail_width=0.5)
arrow = FancyArrowPatch((0, 0), (1, 1), mutation_scale=25, arrowstyle=style, color='k')
ax.add_patch(arrow)
plt.xlim(-0.1, 1.1)
plt.ylim(-0.1, 1.1)
现在可以根据需要调整各种参数以获得所需的结果(例如head_width
,,,,head_length
... mutation_scale
)
此代码段使用以下代码重现给定的情节matplotlib.patches.FancyArrow
:
from matplotlib.patches import FancyArrow
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
v = [-0.2, 0, .2, .4, .6, .8, 1]
for i, overhang in enumerate(v):
arrow = FancyArrow(0, overhang, 1, 0, width = 0.001, head_width=0.1, head_length = None, color = 'k', overhang = overhang)
ax.add_patch(arrow)
ax.set_xticks([])
ax.set_yticks(v)
ax.set_ylim(-0.3,1.1)
ax.set_xlim(-0.5, 2)
ax.set_ylabel("overhang")
推荐阅读
- c# - 用于类似 EditForm 属性的 Blazor WASM 可重复 RenderFragment
- unreal-engine4 - 宏内的变量
- pandas - 在 Pandas DataFrame 中将 rpy2 的 NALogicalType 识别为 NaN
- google-maps - 如何从谷歌地图 api 中分离出原始评论和翻译评论
- spring - 在 LDAP 中通常如何处理空的用户和组基本 DN
- node.js - 有没有过滤mongodb数据的方法?
- snowflake-cloud-data-platform - 在雪花查询中遇到除以零错误
- oracle - 查找最高平均工资列表,部门明智,同时显示最高平均工资和部门ID
- javascript - ESlint - 错误:必须使用导入来加载 ES 模块
- elasticsearch - jboss-eap 的 Fluentd 正则表达式