def drawArrow(A, B):
fig = plt.figure(figsize=(5, 5))
print("xasxcsasdc")
ax = fig.add_subplot(121)
# fc: filling color
# ec: edge color
"""第一种方式"""
ax.arrow(A[0], A[1], B[0]-A[0], B[1]-A[1],
width=0.01,
length_includes_head=True, # 增加的长度包含箭头部分
head_width=0.25,
head_length=1,
fc='r',
ec='b')
ax.set_xlim(0, 5)
ax.set_ylim(0, 5)
ax.grid()
ax.set_aspect('equal')
"""第二种方式"""
# 这种方式是在图上做标注时产生的
# Example:
ax = fig.add_subplot(122)
ax.annotate("",
xy=(B[0], B[1]),
xytext=(A[0], A[1]),
# xycoords="figure points",
arrowprops=dict(arrowstyle="->", color="r"))
ax.set_xlim(0, 5)
ax.set_ylim(0, 5)
matplotlib 画箭头的两种方式
最新推荐文章于 2025-04-01 09:38:36 发布