0

Here is the code snippet:

fig, ax = plt.subplots(figsize=(30, 20)) ax.axis('equal') ax.set(xlim=(-10, 10), ylim=(-10, 10)) circle = plt.Circle((0, 0), 3.1, fc='cyan') ax.add_patch(circle) def kex(N): alpha=2*np.pi/N alphas = alpha*np.arange(N) coordX = np.cos(alphas) coordY = np.sin(alphas) return np.c_[coordX, coordY, alphas] data = 'P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14'.split(' ') radius = 3.3 points = kex(len(data)) for i in range(0, len(data)): a = points[i,2] x,y = (radius*np.sin(a), radius*np.cos(a)) a = a - 0.5*np.pi if points[i, 1] < 0: a = a - np.pi ax.text(x, y, data[i], rotation=np.rad2deg(a), ha="center", va="center", fontsize=15) ax.axis("off") plt.show() 

I want to place the text around a circle but does not seem to find correct rotation values. Some code is taken from here I have tweaked some bits in the code but does not seem to find the correct rotation values. Can someone help?

Output is: enter image description here

Edit 01:

I want something like this screenshot taken from here.

enter image description here

1
  • Your radius is 3.3 instead of 3.2. Commented Aug 5, 2020 at 18:26

1 Answer 1

4

You don't say exactly what your intended output should be. If its that the bottom of each text label lines up with the tangent of the circle, you are almost there; you can do this:

for i in range(0, len(data)): a = points[i,2] x,y = (radius*np.sin(a), radius*np.cos(a)) ax.text(x, y, data[i], rotation=-np.rad2deg(a), ha="center", va="center", fontsize=15) 

i.e. remove the lines of code which modify a after you calculate x and y, and then use minus the angle a to set the rotation of the text.

enter image description here

To answer the edited question, you can simply use:

 if y < 0: a += np.pi 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.