[英]Keep indices in a scatter plot of jaccard distance matrix
I have a disstance matrix and I wanted to plot it as 2D scatter plot. 我有一个距离矩阵,我想将其绘制为2D散点图。
I have found a way through sklearn.manifold: 我已经找到了通过sklearn.manifold的方法:
mds = MDS(n_components=2, dissimilarity='precomputed')
X_r = mds.fit(jac_sim).embedding_
plt.figure()
plt.scatter(X_r[:,0],X_r[:,1],c="red")
plt.savefig((args.Directory + "/MDS2.svg"), format = "svg")
With jac_sim being my disstance matrix that looks something like this: 使用jac_sim作为我的距离矩阵,如下所示:
This code gives me the next plot: 这段代码给了我下一个情节:
I would like to carry the names of the columns or indices from the disstance matrix so I can color code the dots in the plot by Indiv number, and be able to put a label. 我想携带距离矩阵中的列或索引的名称,以便我可以按Indiv编号对图中的点进行颜色编码,并可以放置标签。 I tried to check the X_r file but it only contains the coordinates of the scatter plot but no info of the origin.
我试图检查X_r文件,但它仅包含散点图的坐标,而没有原点的信息。
How can I color code it by column/index name? 如何按列/索引名称对代码进行颜色编码?
If you know the size of your jac_sim
will not change, you always know where are the Indiv numbers, so you could do two scatters using different slices of the data: 如果您知道
jac_sim
的大小不会改变,那么您始终知道jac_sim
编号在哪里,因此您可以使用不同的数据切片进行两次散布:
mds = MDS(n_components=2, dissimilarity='precomputed')
X_r = mds.fit(jac_sim).embedding_
plt.figure()
plt.scatter(X_r[:3:,0],X_r[:3:,1],c="red")
plt.scatter(X_r[3::,0],X_r[3::,1],c="blue")
plt.savefig((args.Directory + "/MDS2.svg"), format = "svg")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.