Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

python - Arrow annotation in an overcrowded scatterplot matplotlib

I am trying to annotate two points in a scatterplot, however due to the overcrowded nature, they become very difficult to see.

Is there anyway I can put an arrow or a pointer that points to the point in question but annotates the name in blank space away from the clustered observations?

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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to specify the location of the annotation text.

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

Resulting image: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...