画出好看的关系图

一、问题描述
计算一个样本这种属性之间的关系热图
以LFWA为例,一共有13143个样本,每个样本有40 个属性(每一个属性取值为0或1)。那么可以获得一个矩阵[13143,40],计算这个矩阵的协方差,并使用seanborn画出热图。
二、代码如下:

import numpy as np
import os
import seaborn as sns
import matplotlib.pyplot as plt
from collections import Counter
from pandas import DataFrame

textpath='/data3/mcs/VideoRecognition/360/LFWA/label.txt'
with open(textpath, 'r') as fd:
    imgs = [list(map(int, x.rstrip().split())) for x in fd.readlines()]

imgs=np.array(imgs).astype(float)
print(imgs.shape)
df = DataFrame(imgs)
corr=df.corr()
plt.figure(figsize=(10,10))
mask=np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)]=True #upper-triangle of mask
cmap=sns.diverging_palette(220,10,as_cmap=True)#色度 饱和度 亮度 生成调色板
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=0.7, square=True, xticklabels=1, yticklabels=1, linewidths=.5, cbar_kws={"shrink":.5})
plt.yticks(rotation=0)
plt.show()

三、效果
效果图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值