python如何实现可视化热力图


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

#fmt(字符串格式代码,矩阵上标识数字的数据格式,比如保留小数点后几位数字)import numpy as np

np.random.seed(0)

x = np.random.randn(4,4)

 

f, (ax1, ax2) = plt.subplots(figsize=(6,6),nrows=2)

 

sns.heatmap(x, annot=True, ax=ax1)

 

sns.heatmap(x, annot=True, fmt='.1f', ax=ax2)

这里写图片描述

热力图矩阵块之间间隔及间隔线参数

1

2

3

4

5

6

7

#linewidths(矩阵小块的间隔),linecolor(切分热力图矩阵小块的线的颜色)import matplotlib.pyplot as plt

f, ax = plt.subplots(figsize = (6,4))

cmap = sns.cubehelix_palette(start = 1, rot = 3, gamma=0.8, as_cmap = True)  

sns.heatmap(pt, cmap = cmap, linewidths = 0.05, linecolor= 'red', ax = ax)  

ax.set_title('Amounts per kind and region')

ax.set_xlabel('region')

ax.set_ylabel('kind')

这里写图片描述

1

2

3

4

5

6

7

8

9

10

11

#xticklabels,yticklabels横轴和纵轴的标签名输出import matplotlib.pyplot as plt

f, (ax1,ax2) = plt.subplots(figsize = (5,5),nrows=2)

 

cmap = sns.cubehelix_palette(start = 1.5, rot = 3, gamma=0.8, as_cmap = True)

 

p1 = sns.heatmap(pt, ax=ax1, cmap=cmap, center=None, xticklabels=False)

ax1.set_title('xticklabels=None',fontsize=8)

 

p2 = sns.heatmap(pt, ax=ax2, cmap=cmap, center=None, xticklabels=2, yticklabels=list(range(5)))

ax2.set_title('xticklabels=2, yticklabels is a list',fontsize=8)

ax2.set_xlabel('region')

这里写图片描述

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

#mask对某些矩阵块的显示进行覆盖

 

f, (ax1,ax2) = plt.subplots(figsize = (5,5),nrows=2)

 

cmap = sns.cubehelix_palette(start = 1.5, rot = 3, gamma=0.8, as_cmap = True)

 

p1 = sns.heatmap(pt, ax=ax1, cmap=cmap, xticklabels=False, mask=None)

ax1.set_title('mask=None')

ax1.set_ylabel('kind')

 

p2 = sns.heatmap(pt, ax=ax2, cmap=cmap, xticklabels=True, mask=(pt<800))  

#mask对pt进行布尔型转化,结果为True的位置用白色覆盖

ax2.set_title('mask: boolean DataFrame')

ax2.set_xlabel('region')

ax2.set_ylabel('kind')

这里写图片描述

用mask实现:突出显示某些数据

1

2

3

4

f,(ax1,ax2) = plt.subplots(figsize=(4,6),nrows=2)

x = np.array([[1,2,3],[2,0,1],[-1,-2,0]])

sns.heatmap(x, annot=True, ax=ax1)

sns.heatmap(x, mask=x < 1, ax=ax2, annot=True, annot_kws={"weight": "bold"})   #把小于1的区域覆盖掉

这里写图片描述

以上就是python如何实现可视化热力图的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

手机有什么Python编译器

pycharm怎么用Python

Python可以做界面吗

Python解释器在语法上不支持什么编程方式

Python如何导入excel

介绍Python判断一个数是不是正小数和整数的方法

Python开发tornado网站之requesthandler:接入点函数

Python遍历输出列表中最长的单词

Python单链表中如何查找和删除节点?

Python映射类型是什么

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...