I’m trying to plot a circle and I want the background to look like a graphing paper, but when I try setting the X and Y limits the lines are messed up. The code for my circles is:
R1 = (n1 + n2 + n3) / 2
circle1 = (0, 0, R1)
circle2 = (0, R1, R1)
circle3 = (0, 2 * R1, 2 * R1)
circle4 = (0, 4 * R1, 2 * R1)
x2 = circle2[0] + circle2[2] * np.cos(theta)
y2 = circle2[1] + circle2[2] * np.sin(theta)
plt.plot(x2, y2, label='Circle 2')
x3 = circle3[0] + circle3[2] * np.cos(theta)
y3 = circle3[1] + circle3[2] * np.sin(theta)
plt.plot(x3, y3, label='Circle 3')
I set the X and Y limits to match what a graphing paper would have. Making the X and Y limits dynamic fixes the issue though. Below is the code for my X and Y limit:
plt.figure(figsize=(6.8, 8.6), dpi=100)
theta = np.linspace(0, 2 * np.pi, 100)
ax = plt.gca()
# Set the limits for x and y axes
ax.set_xlim(-17.5, 17.5)
ax.set_ylim(0, 50)
but the result I get on the figure looks as such:
The output
New contributor
Angelo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.