In the pyplot below, many of the items occupy a very similar spot, so that the annotations overlap. I moved the annotations a random distance away from each item but that looks strange in sparse areas and still isn't enough in dense areas. I could implement some kind of spring based physics layout to prevent labels from colliding but that seems like overengineering for such a simple problem. Is there any existing mechanism to prevent item labels from overlapping?
def randompoint():
deg = 2 * math.pi * random.random()
R = 80
return (math.cos(deg)*R,math.sin(deg)*R)
for i in range(len(D)):
plt.annotate(items[i]["label"], xy=data[i],xytext=randompoint(),textcoords="offset points", arrowprops=dict(facecolor='black', shrink=0.05, width=0.01, headwidth=0.01))