基于python matplotlib绘制带有刻度的箭头,条件是:①先使用plt.imshow()显示一张图作为背景图;②其次,在背景图上任意指定两点之间绘制矢量箭头,且箭头的线段部分,可以显示坐标刻度。③注:虽然可以利用坐标轴的旋转,或者浮动等绘制带有刻度的箭头,但是想要将带有刻度的箭头锚定在图像上的指定位置,却不知如何实现?
#ç»å¶ç®å¤´ä¾å
def arrow():
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.style.use('seaborn-deep')
fig = plt.figure(figsize=(16, 9),dpi=75)
ax = fig.add_subplot(121)
x=np.array([1,2,3,4])
y=np.array([2,4,6,8])
ax.plot(x,y,color = 'b')
ax.annotate("",
xy=(4.5, 9),
xytext=(4, 8),
arrowprops=dict(arrowstyle="->", color="r"))
# 设置Xè½´ãYè½´æ大åæ
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.grid()
ax.set_aspect('equal')
plt.title("è¶å¿å±ç¤ºå¾")
plt.show()
arrow()