2017-09-27 155 views
0

我想在散点图注释两分,但由于过度拥挤的性质,它们变得很难看。箭头标注matplotlib

反正我可以把箭头或指向点问题,但在诠释空白的名字从聚类的观测远指针?

enter image description here

plt.scatter(afb[:,0], afb[:,1], c="yellow") 
plt.title("Arrow Scatter", weight="bold", fontsize=20) 
plt.annotate("James", (a[812,0], a[812,1])) 
plt.annotate("Jane", (a[1067,0], a[1067,1])) 
plt.ylabel("2", fontsize=16) 
plt.xlabel("1", fontsize=16) 
plt.show() 

感谢

回答

1

你需要指定注释文本的位置。

import matplotlib.pyplot as plt 

xy = range(20) 
plt.scatter(xy, xy, c='green', vmin=0, vmax=20, s=20) 
plt.title("Arrow Scatter", weight="bold", fontsize=20) 

# prep anno-text data 
text_location = (2,15) 
target_point = (xy[8],xy[8]) 

plt.annotate("Jane", target_point, text_location, 'data', \ 
       arrowprops=dict(arrowstyle="-|>", \ 
       connectionstyle="angle3", lw=1), \ 
       size=16, ha="center") 

plt.ylabel("2", fontsize=16) 
plt.xlabel("1", fontsize=16) 
plt.show() 

产生的图像: enter image description here