python heatmap总结

article/2025/10/30 23:34:55

基础使用

import seaborn as sns; sns.set_theme(color_codes=True)
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)

在这里插入图片描述

取消行列分类树

import seaborn as sns; sns.set_theme(color_codes=True)
import matplotlib.pyplot as plt 
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
g.ax_row_dendrogram.set_visible(False) 
plt.show()## 取消color分类树g = sns.clustermap(iris)
g.ax_col_dendrogram.set_visible(False) 
plt.show()

在这里插入图片描述
在这里插入图片描述

不显示矩阵横轴标签和纵轴标签

import seaborn as sns; sns.set_theme(color_codes=True)
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris,xticklabels=False)
plt.show()g = sns.clustermap(iris,yticklabels=False)
plt.show()g = sns.clustermap(iris,xticklabels=False,yticklabels=False)
plt.show()

在这里插入图片描述在这里插入图片描述在这里插入图片描述

不显示colorbar的legend

import seaborn as sns; sns.set_theme(color_codes=True)
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
g.cax.set_visible(False)
plt.show()

在这里插入图片描述

添加颜色的cluster块

import seaborn as sns; sns.set(color_codes=True)
import matplotlib.pyplot as plt
import pandas as pd
iris = sns.load_dataset("iris")
species = iris.pop("species")colors_use=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#bcbd22', '#17becf', '#aec7e8', '#ffbb78', '#98df8a', '#ff9896', '#bec1d4', '#bb7784', '#0000ff', '#111010', '#FFFF00',   '#1f77b4', '#800080', '#959595', '#7d87b9', '#bec1d4', '#d6bcc0', '#bb7784', '#8e063b', '#4a6fe3', '#8595e1', '#b5bbe3', '#e6afb9', '#e07b91', '#d33f6a', '#11c638', '#8dd593', '#c6dec7', '#ead3c6', '#f0b98d', '#ef9708', '#0fcfc0', '#9cded6', '#d5eae7', '#f3e1eb', '#f6c4e1', '#f79cd4']# 添加列
col_colors=colors_use[:4] # 
g = sns.clustermap(iris, col_colors=col_colors,cmap="mako", yticklabels=False, xticklabels=False)
plt.show()

在这里插入图片描述

行列排序

import pandas as pd 
import numpy as np 
# read_file="/Users/xiaokangyu/Desktop/scDML_project/论文材料准备/heatmap_picture/cluster_link_conectivity.csv"
# df=pd.read_csv(read_file,index_col=0)
# df.to_csv("./test_sim.txt",index=None,sep=',',mode='w')#可以自己先写入这个以,分割的数据,然后自己添加]表示
# df  
val=[[
0.0,0.0,1.105,0.0,0.0,0.0,1.587,1.591,0.0,0.002,1.494,1.686,0.0,1.452,0.0,0.0,0.0,0.0,0.812,0.0],
[0.0,0.0,0.004,0.0,1.67,0.515,0.0,0.0,0.0,0.009,0.0,0.0,0.0,0.0,2.657,1.228,0.0,0.0,0.0,1.786],
[1.105,0.004,0.0,0.0,0.031,0.003,0.938,0.708,0.009,0.009,0.74,1.312,0.033,0.874,0.008,0.0,0.0,0.02,0.576,0.024],
[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,2.342,2.991,0.0,0.0,1.542,0.0,0.0,0.0,0.8,1.735,0.0,0.357],
[0.0,1.67,0.031,0.0,0.0,1.456,0.0,0.0,0.002,0.002,0.0,0.0,0.003,0.0,3.234,1.738,0.0,0.0,0.0,0.405],
[0.0,0.515,0.003,0.0,1.456,0.0,0.0,0.0,0.0,0.002,0.0,0.0,0.0,0.0,0.367,0.82,0.035,0.0,0.007,0.048],
[1.587,0.0,0.938,0.0,0.0,0.0,0.0,0.704,0.0,0.0,1.424,1.618,0.0,0.545,0.0,0.0,0.0,0.0,0.826,0.0],
[1.591,0.0,0.708,0.0,0.0,0.0,0.704,0.0,0.0,0.004,1.313,0.266,0.0,0.535,0.0,0.0,0.0,0.02,0.688,0.0],
[0.0,0.0,0.009,2.342,0.002,0.0,0.0,0.0,0.0,1.425,0.007,0.0,2.196,0.003,0.0,0.0,0.729,0.558,0.0,0.81],
[0.002,0.009,0.009,2.991,0.002,0.002,0.0,0.004,1.425,0.0,0.0,0.002,0.127,0.003,0.0,0.0,0.476,1.014,0.0,0.333],
[1.494,0.0,0.74,0.0,0.0,0.0,1.424,1.313,0.007,0.0,0.0,0.855,0.0,0.159,0.0,0.0,0.0,0.014,1.986,0.0],
[1.686,0.0,1.312,0.0,0.0,0.0,1.618,0.266,0.0,0.002,0.855,0.0,0.0,0.525,0.0,0.0,0.0,0.0,0.049,0.0],
[0.0,0.0,0.033,1.542,0.003,0.0,0.0,0.0,2.196,0.127,0.0,0.0,0.0,0.003,0.0,0.0,0.4,0.163,0.0,0.19],
[1.452,0.0,0.874,0.0,0.0,0.0,0.545,0.535,0.003,0.003,0.159,0.525,0.003,0.0,0.0,0.0,0.024,0.007,0.215,0.0],
[0.0,2.657,0.008,0.0,3.234,0.367,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.112,0.0,0.0,0.0,0.0],
[0.0,1.228,0.0,0.0,1.738,0.82,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.112,0.0,0.0,0.0,0.0,0.095],
[0.0,0.0,0.0,0.8,0.0,0.035,0.0,0.0,0.729,0.476,0.0,0.0,0.4,0.024,0.0,0.0,0.0,2.401,0.09,0.071],
[0.0,0.0,0.02,1.735,0.0,0.0,0.0,0.02,0.558,1.014,0.014,0.0,0.163,0.007,0.0,0.0,2.401,0.0,0.069,0.0],
[0.812,0.0,0.576,0.0,0.0,0.007,0.826,0.688,0.0,0.0,1.986,0.049,0.0,0.215,0.0,0.0,0.09,0.069,0.0,0.0],
[0.0,1.786,0.024,0.357,0.405,0.048,0.0,0.0,0.81,0.333,0.0,0.0,0.19,0.0,0.0,0.095,0.071,0.0,0.0,0.0]
]
arr=np.array(val)
df=pd.DataFrame(data=arr)
#df
sns.clustermap(df)
plt.show()sns.clustermap(df,row_cluster=False)# 不进行行聚类
plt.show()

在这里插入图片描述在这里插入图片描述


http://chatgpt.dhexx.cn/article/cn7ncaDd.shtml

相关文章

seaborn绘制heatmap

【seaborn.heatmap整理】 用处:将数据绘制为颜色方格(编码矩阵)。 引用形式: seaborn.heatmap(data, vminNone, vmaxNone, cmapNone, centerNone, robustFalse, annotNone, fmt’.2g’, annot_kwsNone, linewidths0, linecolor‘…

Heatmap

前言 目前所说的模型可视化或者模型可解释说到是对某一类别具有可解释性,直接画出来特征图并不能说明模型学到了某种特征,对一个深层的卷积神经网络而言,通过多次卷积和池化以后,它的最后一层卷积层包含了最丰富的空间和语义信息…

R | 可视化 | 热图(Heatmap)

1 基础绘制 R绘制热图时&#xff0c;数据需要输入一个矩阵&#xff0c;可以用as.matrix()把它转换成矩阵。这里利用R自带的数据集绘制热图。 > # 数据 > data <- as.matrix(mtcars) > > # 绘制热图 > heatmap(data) OUTPUT: 热图的每一列是一个变量&…

科研作图-heatmap(一)

1.简介 在科研中有很多地方为了可解释给审稿人提供了热图,便于知道深度学习中到底是哪部分在起作用,或者是在机器学习中分析不同的特征之间是否存在相关性?存在多大的相关性;或者是直观的展示场景热力图…总之,用处很多,我正好现在也需要用,就先总结下:绘制HeatMap的库有很多,…

「C#」生成HeatMap(热度图)的实现

1、什么是Heatmap 其实不用多言&#xff0c;需要这个的人自然知道这是什么。基于一系列点生成的热度图&#xff0c;放张图感受一下&#xff1a; ma...大概就是这种样子。 2、生成&#xff08;计算&#xff09;原理 实现方式实际上是在每个点上叠加高斯矩阵。高斯矩阵就是在二…

关键点检测的heatmap介绍

开始学关键点检测的时候&#xff0c;到处找找不到heatmap的解释。现在大概有些懂了&#xff0c;干脆自己写一个。部分转载。 关键点定位任务两种做法&#xff1a;heatmap和fully connected回归&#xff08;Heapmap-based和Regression-Based&#xff09; heatmap得到一张类似热…

python绘制热度图(heatmap)

1、简单的代码 from matplotlib import pyplot as plt import seaborn as sns import numpy as np import pandas as pd#练习的数据&#xff1a; datanp.arange(25).reshape(5,5) datapd.DataFrame(data)#绘制热度图&#xff1a; plotsns.heatmap(data)plt.show() 查看效果&a…

热图(Heatmap)绘制(matplotlib与seaborn)

热图是数据统计中经常使用的一种数据表示方法&#xff0c;它能够直观地反映数据特征&#xff0c;查看数据总体情况&#xff0c;在诸多领域具有广泛应用。 一&#xff1a;matplotlib绘制方法 1.基础绘制 热图用以表示的是矩阵数据&#xff0c;例如相关阵、协差阵等方阵&#…

‘0’ 和 '\0'

48是0对应的ascii值。

KEIL/MDK编译优化optimization选项注意事项

KEIL编译器C语言编译选项优化等级说明 -Onum Specifies the level of optimization to be used when compiling source files. Syntax -Onum Where num is one of the following: 0 Minimum optimization. Turns off most optimizations. When debugging is enabled, this opt…

0,'\0','0'

#include <iostream> using namespace std; int main(void) { cout<<__FILE__<<\t<<__LINE__<<endl;cout<<"内 容:\t"<<"0"<<\t<<"\\\0\"<<\t<<"\0\"<<…

Odoo

狭路相逢 勇者胜 Odoo 是用于经营公司的最好的管理软件。 数百万用户使用我们的集成应用可以更好地开展工作 现在开始。免费的。 重新定义可扩展性 一个需求&#xff0c;一个应用程式。整合从来没有那么顺畅 促进销售量 客户关系管理POS销售 整合您的服务 项目工时表帮助…

0 、 '0' 、 0 、 ’\0’ 区别

转载自&#xff1a;https://blog.csdn.net/qnavy123/article/details/93901631 ① ‘0’ 代表 字符0 &#xff0c;对应ASCII码值为 0x30 (也就是十进制 48) ② ‘\0’ 代表 空字符(转义字符)【输出为空】 &#xff0c;对应ASCII码值为 0x00(也就是十进制 0)&#xff0c; …

Linux的内核编译用O0是编译不过的

最近在ATF的升级过程中遇到了一个编译问题&#xff0c;最后是通过编译优化解决的&#xff0c;然后一百度这个优化全是在Linux中的。于是就借着Linux编译优化来学学。 内容来自 宋宝华老师&#xff1a; 关于Linux编译优化几个必须掌握的姿势 1、编译选项和内核编译 首先我们都…

alert uuid does not exits. Dropping to a shell!

ALERT&#xff01;UUID does not exit. Dropping to a shell&#xff01; 服务器系统ubuntu16.04server&#xff0c;非自然断电后开机进入initramfs模式&#xff0c;服务器磁盘阵列是raid1和raid5。初步分析是硬盘坏道或掉盘&#xff0c;进入raid卡里看到硬盘一切正常&#xf…

跟着团子学SAP PS:如何查询PS模块中的user exits以及相关BAdIs SE80/SMOD/CNEX006/CNEX007/CNEX008

在PS很多标准字段或功能无法满足客户需求的时候往往需要通过SAP标准的user exits或者BAdI进行开发以满足业务需要&#xff0c;所以今天介绍下如何查询PS模块中的用户出口以及BAdIs&#xff1a; &#xff08;1&#xff09;查询PS模块中的user exits: 执行SE80&#xff0c;在菜…

EXT

ext的核心是store&#xff0c;存储数据用的。调试时可以先把store这块先屏蔽掉&#xff0c;先看页面的&#xff0c;页面出来了再调试store。这样会调试起来很快。 init: function () { var view this.getView(), // var store Global.getStore(app.store.L…

IDEA|class path resource XXX cannot be opened because it does not exits

IDEA|class path resource XXX cannot be opened because it does not exits 问题截图&#xff1a; 原因&#xff1a;没有设置好各个文件夹。我的理解是&#xff0c;当把文件夹设置好具体的功能才能被IDEA自动识别。 解决方法&#xff1a; 转发链接&#xff1a;https://bl…

User Exits和Customer Exits

一、Extension of SAP functionality SAP makes different possibilities available to extend SAP functionality in the R/3 without modifying the delivered R/3-Standard. Thus these extensions are further present also after a R/3-Release-Wechsel. User exit Fi…

sql查询中使用in和exits比较和区别

首先&#xff0c;查询中涉及到的两个表&#xff0c;一个user和一个order表&#xff0c;具体表的内容如下&#xff1a; user表&#xff1a; order表&#xff1a; in 确定给定的值是否与子查询或列表中的值相匹配。in在查询的时候&#xff0c;首先查询子查询的表&#xff0c;然后…