如何使中心的颜色使用相同的簇颜色?
我有两种方法用于绘制群集的中心
def draw_roh_delta(self, rho, delta, center, plot):
plot.scatter(rho, delta, label='rho-delta', c='k', s=5)
plot.set_xlabel('rho')
plot.set_ylabel('delta')
center_rho = rho[center]
center_delta = delta[center]
np.random.seed(6)
colors = np.random.rand(len(center), 3)
plot.scatter(center_rho, center_delta, c=colors)
plot.legend()
,还有其他用于绘制群集
def draw_cluster(self, title, cluster, halo, points, plot):
cluster_points = dict()
colors = dict()
np.random.seed(10)
for k, v in cluster.items():
cluster_points[k] = points.loc[cluster[k], :]
colors[k] = np.random.rand(3)
for k, v in cluster_points.items():
plot.scatter(v.loc[:, 'x'], v.loc[:, 'y'], c=colors[k], alpha=0.5)
plot.scatter(v.at[k, 'x'], v.at[k, 'y'], c=colors[k], s=np.pi * 10 ** 2)
的方法,我需要使中心的颜色与簇相同,而不是随机创建它们。有人可以帮忙吗?
编辑
def draw_roh_delta(self, rho, delta, center, plot):
plot.scatter(rho, delta, label='rho-delta', c='k', s=5)
plot.set_xlabel('rho')
plot.set_ylabel('delta')
center_rho = rho[center]
center_delta = delta[center]
color= ['red', 'blue', 'green', 'yellow','orange','purple']
plot.scatter(center_rho, center_delta, c=color)
plot.legend()
i have two methods one for drawing the centers for the cluster
def draw_roh_delta(self, rho, delta, center, plot):
plot.scatter(rho, delta, label='rho-delta', c='k', s=5)
plot.set_xlabel('rho')
plot.set_ylabel('delta')
center_rho = rho[center]
center_delta = delta[center]
np.random.seed(6)
colors = np.random.rand(len(center), 3)
plot.scatter(center_rho, center_delta, c=colors)
plot.legend()
and others for drawing the cluster
def draw_cluster(self, title, cluster, halo, points, plot):
cluster_points = dict()
colors = dict()
np.random.seed(10)
for k, v in cluster.items():
cluster_points[k] = points.loc[cluster[k], :]
colors[k] = np.random.rand(3)
for k, v in cluster_points.items():
plot.scatter(v.loc[:, 'x'], v.loc[:, 'y'], c=colors[k], alpha=0.5)
plot.scatter(v.at[k, 'x'], v.at[k, 'y'], c=colors[k], s=np.pi * 10 ** 2)
I need to make the color of the centers the same color as the clusters instead of creating them randomly. can someone help, please?
EDIT
def draw_roh_delta(self, rho, delta, center, plot):
plot.scatter(rho, delta, label='rho-delta', c='k', s=5)
plot.set_xlabel('rho')
plot.set_ylabel('delta')
center_rho = rho[center]
center_delta = delta[center]
color= ['red', 'blue', 'green', 'yellow','orange','purple']
plot.scatter(center_rho, center_delta, c=color)
plot.legend()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用
绘图
函数来绘制点,该函数返回list [line2d]
。您只需要取出第一个元素并调用其get_color()
方法即可获得这次绘制的颜色。我从Kmeans聚类中提取了我的结果:
不幸的是,要做到这一点,您可能需要将这两种方法融合在一起,或者让第一种方法将所有颜色返回第二种方法。
edit
我会这样解决:
我不知道您的
plot
的类型,所以我假设它是matplotlib.pyplot.axes.axes
,而且我认为您绘制中心的顺序与绘制簇的顺序一致。One way is to use the
plot
function to draw points, which returns alist[Line2d]
. You just need to take out the first element and call itsget_color()
method obtains the color drawn this time.I drew my result of kmeans clustering as follow:
Unfortunately, to do this, you may need to blend the two methods together, or let the first method return all colors to the second method.
EDIT
I would solve it like this:
I don't know the type of your
plot
, so I assume it'smatplotlib.pyplot.Axes
, and I assume that the order in which you draw the centers is consistent with the order in which you draw the clusters.