【无标题】

用T-SNE算法和Scatter方法使高维数据可视化

import random
from mpmath import arange
import numpy as np
import pickle as Pickle
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

zx = np.array(pd.read_csv("dplb_zx.csv"))
zy = np.array(pd.read_csv("dplb_zy.csv"))
Y = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, \
         10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, \
         17, 17, 18, 18, 19, 19]

def tsenVisual(big,end):
    arr = np.empty(shape=(40, 80))
    i = 0
    for item in range(big, end):
        arr[i] = zx[item]
        i += 1
        arr[i] = zy[item]
        i += 1
    return arr

arr = tsenVisual(20,40)
X_embedded = TSNE(n_components=2,init="pca").fit_transform(arr)

#为40个点配置颜色 两两一组,需要二十种颜色
def get_color(labels):
    #colors=["r","b","g","y","o"]
    colors=["dimgray","darkorange","tan","silver","forestgreen",\
             "darkgreen","royalblue","navy","red","darksalmon",\
             "peru","olive",\
             "yellow","cyan","mediumaquamarine","skyblue","purple","fuchsia",\
             "indigo","khaki"]
    color=[]
    for i in range(len(labels)):
        color.append(colors[labels[i]])
    return color

figure=plt.figure(figsize=(5,5),dpi=1200)
color=get_color(Y)#为40个点配置颜色
x=X_embedded[:,0]#横坐标
y=X_embedded[:,1]#纵坐标

#关闭坐标刻度
plt.xticks([])
plt.yticks([])
#关闭坐标轴
plt.axis('on')
#显示子图边框
plt.box(on=True)
#绘制散点图。
plt.scatter(x,y,color=color)

plt.savefig("dplb20-40.png")
plt.show()

引用:https://blog.csdn.net/qq_43391414/article/details/120666927

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值