• python plot绘图


    使用python绘制t-sne图,并保存

    一下是一个将que_im_features向量可视化的例子:

    def emb_save(que_im_features,i):# 向量[75, 640, 11, 11], episode
        import numpy as np
        import pandas as pd
        from sklearn import manifold
        import matplotlib.pyplot as plt
    
        que_im_features = que_im_features.mean(-1) #[75, 640,11,11]-> [75, 640]变成二维
        que_im_features = que_im_features.mean(-1)
    
    
        vec_list = que_im_features.cpu().numpy()
        vec_array = np.array(vec_list)
        tsne = manifold.TSNE(n_components=2, init='pca', random_state=42,perplexity=8,learning_rate=515,n_iter=50000).fit_transform(vec_array)
        # print("tsne:",tsne)
        # tsne 归一化, 这一步可做可不做
        x_min, x_max = tsne.min(0), tsne.max(0)
        tsne_norm = (tsne - x_min) / (x_max - x_min)
    
    
        tsne_1 = tsne_norm[0:50]#每类50个
        tsne_2 = tsne_norm[50:100]
    
    
        plt.figure(figsize=(7, 7))#图大小
        plt.scatter(tsne_1[:, 0], tsne_1[:, 1], 30,  label='Brown Creeper')
        # tsne_normal[i, 0]为横坐标,X_norm[i, 1]为纵坐标,1为散点图的面积, color给每个类别设定颜色
        plt.scatter(tsne_2[:, 0], tsne_2[:, 1], 30,  label='Rusty Blackbird')
    
        plt.legend(loc="lower right",prop={'size': 14})#图例设置,位置右下,大小为14号
    
        plt.xticks( size=16)#横轴字大小
        plt.yticks( size=16)
        plt.savefig("./Picture"+str(i)+".pdf",bbox_inches='tight')#保存为pdf
        					# bbox_inches='tight'输出图像周围空白比边距减小
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    在这里插入图片描述

  • 相关阅读:
    Passper for Excel v3.7.3.4 Excel 密码恢复工具
    SpringBoot学习笔记(1)——B站动力节点
    【无标题】
    flutter,uni-app开发调试ios
    Hadoop生态之Yarn
    C++实战项目-网络编程基础包含TCP详解
    ili9431液晶 tft_espi图形库演示 时钟、天气、滚动、气象图标
    面向对象设计模式
    JavaScript中的类型转换
    17.应用负载压力测试
  • 原文地址:https://blog.csdn.net/weixin_44040169/article/details/134538584