在每个点在 matplotlib 中注释
Annotating in matplotlib at each point
我正在研究雷达传感器。每次从传感器获取数据时,我都会绘制数据。我想用它的特征来注释每个点,例如 x.y.z。我该怎么做?
我知道 ax.annotate 但我一次可以做 1 点。如果我循环此命令,它会减慢我的程序。这就是我要实现的目标:
我得到了我自己问题的答案。
我们需要在循环中使用 .set_text() 命令来更新文本(点的特征)。摘要代码如下:
fig1=plt.figure(figsize=(15,32))
ax1=fig1.add_subplot(111, aspect='equal')
ax1.grid(True)
Ln, = ax1.plot(plot_x,plot_y,'ro') #plot_X,plot_y are lists of points
plt.ion() # to make figure interactive
plt.show()
......
......
......
Ln.set_data(plot_x,plot_y) #to updates points in the lists
for i in range(len(plot_ann)): #each time plot_ann number will change
if i >= len(ann_objs): #ann_objs is annotation object list
ann_objs.append(ax1.annotate("", xy=(0,0)))
ann_objs[i].set_text(plot_ann[i])
ann_objs[i].xy = (plot_x[i], plot_y[i])
ann_objs[i].xyann = (plot_x[i]+0.2, plot_y[i]+0.2)
我正在研究雷达传感器。每次从传感器获取数据时,我都会绘制数据。我想用它的特征来注释每个点,例如 x.y.z。我该怎么做?
我知道 ax.annotate 但我一次可以做 1 点。如果我循环此命令,它会减慢我的程序。这就是我要实现的目标:
我得到了我自己问题的答案。
我们需要在循环中使用 .set_text() 命令来更新文本(点的特征)。摘要代码如下:
fig1=plt.figure(figsize=(15,32))
ax1=fig1.add_subplot(111, aspect='equal')
ax1.grid(True)
Ln, = ax1.plot(plot_x,plot_y,'ro') #plot_X,plot_y are lists of points
plt.ion() # to make figure interactive
plt.show()
......
......
......
Ln.set_data(plot_x,plot_y) #to updates points in the lists
for i in range(len(plot_ann)): #each time plot_ann number will change
if i >= len(ann_objs): #ann_objs is annotation object list
ann_objs.append(ax1.annotate("", xy=(0,0)))
ann_objs[i].set_text(plot_ann[i])
ann_objs[i].xy = (plot_x[i], plot_y[i])
ann_objs[i].xyann = (plot_x[i]+0.2, plot_y[i]+0.2)