Python 根据距离均匀分散固定中心周围的坐标

Python evenly scatter coordinates around fixed center based on distance

我想根据每个数据点到中心的给定距离,将许多数据点散布在一个中心 (2.5,2.5) 周围。 我该怎么做才能在中心周围均匀地躲避 duplicates/scatter 它们?

提前致谢

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(6, 6))

N = 120
angles = np.linspace(0, 2 * np.pi, N)
c_x, c_y = (2.5, 2.5)
x_s, y_s = [], []


distances = list(np.arange(0, 5.5, 0.5))

for distance in distances:
    for angle in angles:
        x_s.append(c_x + distance * np.cos(angle))
        y_s.append(c_y + distance * np.sin(angle))

    plt.scatter(x_s, y_s, c="b", s=4)
plt.show()

import cmath
import numpy as np
from matplotlib import pyplot as plt
from itertools import starmap

c = np.array(list(starmap(cmath.rect, [(v//40+1, v*np.pi/20) for v in range(120)])))
x = c.real+2.5
y = c.imag+2.5
plt.scatter(x, y)

澄清一下,我想要每个距离一个点,然后下一个偏移 180 或 90 度。但是我根据Gustav Rasmussen提供的代码成功完成了它:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(6, 6))

#default
N = 50

angles = np.linspace(0, 2 * np.pi, N)
c_x, c_y = (2.5, 2.5)
x_s, y_s = [], []

distances = list(np.arange(0, 5.5, 0.01))
i = angles.size/4

for distance in distances:
    x_s.append(c_x + distance * np.cos(i))
    y_s.append(c_y + distance * np.sin(i))
    i += i
    plt.scatter(x_s, y_s, c="b", s=4)
plt.show()

在这里我们可以看到 550 个距离,显示的距离与下一个显示偏移大约 90 度。

最后提到:在处理偏差较大的数据集时,最好i = angles.size/2 使输出保持圆圈