如何获取带有特征标签的tSNE图?

时间:2019-05-18 00:30:27

标签: python matplotlib plot scikit-learn label

我有一个包含细胞类型和基因表达值的csv文件。我想获得一个tSNE群集图,其中包含每种单元格类型(只有21种单元格类型)的图例/标签(Ex1,Ex2,Ex3,...等),因此该图应该只有21个点,每个点对应一个单元格类型)。 我尝试了很多方法,但无法获得带有标签的tsne图。谁能帮我修改代码以包括标签?另外,对每个点使用不同的颜色代码会更好。

csv文件的外观如下:

  ABCA1, ABCA3, TEME

Ex1, 1.1,   2.3,   0.4, ...

Ex2, 0.6,   0.9,   1.4, ...

Ex3, 0.8,   1.5,   2.0, ...

... ...

这是代码的一部分:

df = pd.read_csv('Genes.csv', index_col=0)
X = df.values
means = X.mean(axis=0) 
stdevs = X.std(axis=0) 
Xcent = X - means
Xnorm = Xcent / stdevs
features = ['ABCA1', 'ABCA3', ..., 'TEME'] #all the genes
df_norm = df.copy()
df_norm[features] = StandardScaler().fit(df_norm[features]).transform(df_norm[features])
X_tsne = TSNE(learning_rate=500, n_components=2).fit_transform(df_norm[features])
figure(figsize=(11, 5))
cmap = plt.get_cmap('nipy_spectral')
scatter(X_tsne[:, 0], X_tsne[:, 1])
title('TSNE')

0 个答案:

没有答案