Skip to content Skip to sidebar Skip to footer

Annotate Text To Axes And Align As A Circle

I am trying to plot text on axes and align this text to a circle. More precisely there are points with different coordiantes (x,y) which are located inside this circle and created

Solution 1:

I don't see what the distance would do in the equation. You want to determine the point at which to locate the annotation and give this point to the annotation function.

import numpy as np
import matplotlib.pyplot as plt

texts=["Dresden","Berlin", "Freiburg"]
xy = np.array([[3.5,1],[3.,2.],[0,-2]])

center = np.array([1.,1.])
radius = 5 # radius

x,y = zip(*xy)
cx, cy = center
plt.scatter(x,y)
plt.scatter(cx, cy)

#plot a cirle
ct = np.linspace(0,2*np.pi)
circx, circy = radius*np.cos(ct)+cx, radius*np.sin(ct)+cy
plt.plot(circx, circy, ls=":")



def ann(x,y, cx, cy, r, text):
    angle = np.arctan2(y-cy, x-cx)
    xt, yt = r*np.cos(angle)+cx, r*np.sin(angle)+cy
    plt.annotate(text, xy=(x,y), xytext=(xt, yt), arrowprops={"arrowstyle":"->"})
    plt.scatter(xt, yt, c=0)

for t, xi,yi in zip(texts, x,y):
    ann(xi,yi, cx, cy, radius, t)

plt.gca().set_aspect("equal")
plt.show()

enter image description here

Post a Comment for "Annotate Text To Axes And Align As A Circle"