Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我想根据群集绘制数据和颜色_Python_Python 3.x - Fatal编程技术网

Python 我想根据群集绘制数据和颜色

Python 我想根据群集绘制数据和颜色,python,python-3.x,Python,Python 3.x,我需要用python绘制我的k-means算法,但我不知道如何绘制,我想绘制,颜色取决于它们的簇 我在网上试过几种代码,但我不懂 我的x和y坐标是sum[0]和sum[1],我的聚类索引是centBaru变量 sum[0]=[30000,50000,50000,4000,......] sum[1]=[0.333333,0.12121,0.232,0.1212211,......] centBaru=contain index cluster 我想要像使用库sklearn一样

我需要用python绘制我的k-means算法,但我不知道如何绘制,我想绘制,颜色取决于它们的簇

我在网上试过几种代码,但我不懂 我的x和y坐标是sum[0]和sum[1],我的聚类索引是centBaru变量

   sum[0]=[30000,50000,50000,4000,......]
   sum[1]=[0.333333,0.12121,0.232,0.1212211,......]
   centBaru=contain index cluster
我想要像使用库sklearn一样的输出

  'plt.scatter(df['x'], df['y'], c= kmeans.labels_.astype(float), s=50, alpha=0.5)
它会给出如下结果:

c:[10200100100]是如何工作的?我的集群是基于列表索引的,所以当我的centBaru index=0时,这意味着sum1[0]在集群1中
import  matplotlib.pyplot as plt
%matplotlib inline 
s['x']: [30000,50000,50000,4000]
s['y']: [0.333333,0.12121,0.232,0.1212211]
s['centBaru']: [0,2,1,1]  # id of claster for each point

# so first point would be (x,y) = (30000, 0.33333) with color Red (i.e.  id of cluster = "0" 

cl = ['r','g','b']  # colors for different clusters


plt.scatter(x = s['x'],y = s['y'], c = [cl[x] for x in s['centBaru']])