+ 3

Difficulty in Plotting circles in Python using Mathplotlib and NumPy.

I have tried plotting a circle in Python but get a distorted curve where there is a circle in the 1st and 4th quadrants but a straight line joining the highest point on the 1st quadrant to the lowest point in the 4th quadrant and I'm unable to get a proper circle. The code is given as: center_1_x = -2 radius_1 = 6 x_values = np.linspace(center_1_x - radius_1, center_1_x + radius_1, 100, endpoint=True) y_values = np.sqrt(abs((radius_1 ** 2) - (x_values - center_1_x) ** 2)) * np.sign(x_values - center_1_x) plt.plot(x_values, y_values, color='blue')

20th Aug 2023, 4:15 AM
Jeevesh Kumar Banchhor
3 odpowiedzi
+ 4
20th Aug 2023, 8:06 AM
JaScript
JaScript - avatar
+ 2
Well by making two values of y_values like y_values_p and y_values_n, I have been able to solve the problem by not considering np.sign statement
20th Aug 2023, 4:34 AM
Jeevesh Kumar Banchhor
+ 1
or you can force a square shaped plot plt.gca().set_aspect('equal') https://code.sololearn.com/cbCT6dsuXY56/?ref=app
20th Aug 2023, 11:05 AM
Bob_Li
Bob_Li - avatar