绘制聚类数据点Python

时间:2018-04-05 16:43:40

标签: python matplotlib plot

我正在进行群集练习,我有一个看起来像这样的列表

[

[(1, 3), (2, 5), (2, 6), (1, 2), (1, 8)],

[(4, 7), (5, 5), (6, 4)]

[(8, 9), (10, 9), (11, 12), (10, 12)]


[(18, 20), (20, 29), (17, 16), (18, 22)]

]

基本上我将集群变成了一个数组数组。我想知道如何在Python上绘制它,不同的簇有不同的颜色。我尝试过使用mathplotlib,但我很困惑。

1 个答案:

答案 0 :(得分:0)

您可以使用plt.scatter

import matplotlib.pyplot as plt
s = [[(1, 3), (2, 5), (2, 6), (1, 2), (1, 8)], [(4, 7), (5, 5), (6, 4)], [(8, 9), (10, 9), (11, 12), (10, 12)], [(18, 20), (20, 29), (17, 16), (18, 22)]]
c = iter(['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'])
for group in s:
   plt.scatter(*zip(*group), color = next(c))

plt.show()

enter image description here