python matplotlib 绘制带有刻度的箭头?

基于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()

温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜