Skip to content
Advertisement

plotting n number of equal points in circular direction in python

I am working on the task in which I have to make a circle which is having n number of equal parts. I am provided with centre and radius of the circle which is (0,0) and 4 respectively. To achieve this task, I have written below code,

JavaScript

However, after running this code, I got output like below which does not seem a coorect which I am suppose to have.

enter image description here

Kindly let me know what I am doing wrong and give some suggestion of correct code. Thank you

Advertisement

Answer

Aside from the fact that you are generating numbers in degrees and passing them to a function that expects radians, there’s a much simpler and less error-prone method for generating evenly-spaced coordinates:

JavaScript

endpoint=False ensures that you end up with 36 partitions rather than 35, since otherwise 0 and 2 * np.pi would overlap.

If you wanted to connect the dots for your circle, you would want the overlap. In that case, you would do

JavaScript

Here is how you would plot a circle with the 36 sectors delineated:

JavaScript

Finally, if you want your circle to look like a circle, you may want to run plt.axis('equal') after plotting.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement