Python 过度拥挤散点图matplotlib中的箭头注释

Python 过度拥挤散点图matplotlib中的箭头注释,python,matplotlib,Python,Matplotlib,我试图在散点图中注释两点,但是由于过度拥挤的性质,它们变得很难看到 我是否可以放置一个箭头或指针,指向问题点,但在空白处注释名称,远离聚集观察 谢谢您需要指定注释文本的位置 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) # pr

我试图在散点图中注释两点,但是由于过度拥挤的性质,它们变得很难看到

我是否可以放置一个箭头或指针,指向问题点,但在空白处注释名称,远离聚集观察


谢谢

您需要指定注释文本的位置

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()
结果图像:
您需要指定注释文本的位置

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()
结果图像: