python 中的散点函数如何用于绘制图形

how scatter function work in python for plotting graph

分散函数在这里是如何工作的?我想知道 c=Y 是什么意思,下面代码中的 X[:,0]X[:,1] 是什么。

#make_blob is data set

X, Y = make_blobs(n_samples=500, centers=2, random_state=0, cluster_std=0.40) 
plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='spring')
plt.show() 

假设 make_blobs 指的是 sklearn.datasets.make_blobs:

X 表示特征数据集,Y 表示相应的标签(目标)。因此,X 中的每一列代表一个特征。

X[:, 0][row, column] 的形式对 X 执行索引,其中 : 表示 "everything"。因此,组合表达式表示"take every row from X in the column with index 0"(即第一列)。

类似地,X[:, 1] 从第二列的 X 中获取每一行。

这些可以一起作为散点图的 x 和 y 坐标。

传递 c=Y 告诉函数您希望根据 Y 的相应值对点进行着色。因此,所有 Y=0 的点都是一种颜色,所有 Y=1 的点都是另一种颜色。