centroids = {
i+1: [np.random.randint(0,80), np.random.randint(0,80)]
for i in range(k)
}
fig = plt.figure(figsize=(10, 5))
plt.scatter(df['x'], df['y'], color='k')
colmap = {1: 'r', 2: 'g', 3: 'b'}
for i in centroids.keys():
plt.scatter(*centroids[i], color=colmap[i])
答案 0 :(得分:1)
在plt.scatter方法中,您想提供一个s参数来定义点的面积,如此处在此问题中所讨论的:pyplot scatter plot marker size
因此,您的上一个循环将需要如下所示:
for i in centroids.keys():
plt.scatter(*centroids[i], color=colmap[i], s=4) # change the s= parameter