有没有办法将外环的点连接到 matplotlib 中的内环?
Is there a way to connect the points of the outer ring to the inner ring in matplotlib?
我有一个代码可以在绘图上绘制两个具有不同半径的圆的点,但是我在用单独的线连接外圆和内圆时遇到问题。我需要将第 i 个外部点连接到第 i 个相应的内部点,这些内部点包含在单个列表中并且在 n 的范围内。我只是坚持如何做到这一点,希望得到任何指导。
import numpy as np
import matplotlib.pyplot as plt
def circle_points(r, n):
points = []
for r, n in zip(r, n):
t = np.linspace(0, 2*np.pi, n, endpoint=True) #finding evenly spaced points from 0 to n
h = (2*np.pi*r)/n #space between each point in meters
x = r * np.sin(t) #converting to circle coordinate on x-axis
y = r * np.cos(t)
for i in range(n):
points.append([x[i],y[i]])
return points
r = [0.1944,0.1444] #radius in meters
n = [30,30] #amount of points in circle
x,y=zip(*circle_points(r,n))
plt.scatter(x,y)
plt.plot(x,y)
plt.axis('equal')
plt.show()
当前结果:
双圆的坐标x和y已经创建。由于数组的前半部分是外圈,后半部分是内圈,所以我们将外圈的第一个数据和内圈的第一个数据组合起来画一条线段。
import numpy as np
import matplotlib.pyplot as plt
def circle_points(r, n):
points = []
for r, n in zip(r, n):
t = np.linspace(0, 2*np.pi, n, endpoint=True) #finding evenly spaced points from 0 to n
h = (2*np.pi*r)/n #space between each point in meters
x = r * np.sin(t) #converting to circle coordinate on x-axis
y = r * np.cos(t)
for i in range(n):
points.append([x[i],y[i]])
print(points)
return points
r = [0.1944,0.1444] #radius in meters
n = [30,30] #amount of points in circle
x,y=zip(*circle_points(r,n))
plt.scatter(x,y)
plt.plot(x,y)
# add line
for i in range(30):
plt.plot([x[i], x[30+i]], [y[i], y[30+i]], color='red')
plt.axis('equal')
plt.show()
我有一个代码可以在绘图上绘制两个具有不同半径的圆的点,但是我在用单独的线连接外圆和内圆时遇到问题。我需要将第 i 个外部点连接到第 i 个相应的内部点,这些内部点包含在单个列表中并且在 n 的范围内。我只是坚持如何做到这一点,希望得到任何指导。
import numpy as np
import matplotlib.pyplot as plt
def circle_points(r, n):
points = []
for r, n in zip(r, n):
t = np.linspace(0, 2*np.pi, n, endpoint=True) #finding evenly spaced points from 0 to n
h = (2*np.pi*r)/n #space between each point in meters
x = r * np.sin(t) #converting to circle coordinate on x-axis
y = r * np.cos(t)
for i in range(n):
points.append([x[i],y[i]])
return points
r = [0.1944,0.1444] #radius in meters
n = [30,30] #amount of points in circle
x,y=zip(*circle_points(r,n))
plt.scatter(x,y)
plt.plot(x,y)
plt.axis('equal')
plt.show()
当前结果:
双圆的坐标x和y已经创建。由于数组的前半部分是外圈,后半部分是内圈,所以我们将外圈的第一个数据和内圈的第一个数据组合起来画一条线段。
import numpy as np
import matplotlib.pyplot as plt
def circle_points(r, n):
points = []
for r, n in zip(r, n):
t = np.linspace(0, 2*np.pi, n, endpoint=True) #finding evenly spaced points from 0 to n
h = (2*np.pi*r)/n #space between each point in meters
x = r * np.sin(t) #converting to circle coordinate on x-axis
y = r * np.cos(t)
for i in range(n):
points.append([x[i],y[i]])
print(points)
return points
r = [0.1944,0.1444] #radius in meters
n = [30,30] #amount of points in circle
x,y=zip(*circle_points(r,n))
plt.scatter(x,y)
plt.plot(x,y)
# add line
for i in range(30):
plt.plot([x[i], x[30+i]], [y[i], y[30+i]], color='red')
plt.axis('equal')
plt.show()