matplot-热力图

博客提供了两个信息技术相关参考链接,一是关于Python实现可视化热力图的内容,另一是数据可视化Seaborn颜色调控篇的教程,为数据可视化学习提供了方向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

示例:
在这里插入图片描述
代码:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

def plot(confusion, xticklabels, yticklabels):
	f, ax1 = plt.subplots(figsize=(10, 6),nrows=1)

	cmap = sns.light_palette("red", as_cmap=True)
	sns.heatmap(confusion, annot=True, ax=ax1, vmax=0, vmin=1, cmap=cmap)

	ax1.set_title('title')
	ax1.set_xlabel('xlabel')
	ax1.set_xticklabels(xticklabels, rotation=90) 
	ax1.set_ylabel('ylabel')
	ax1.set_yticklabels(yticklabels, rotation=0)

	f.savefig('heatmap.jpg', bbox_inches='tight')


def normalization(x):
    x_sum = np.sum(x, axis = 1, keepdims = True)
    result = x / x_sum    
    return result

if __name__ == '__main__':
	n = 10
	matrix = np.random.random((n,n))
	matrix = normalization(matrix)
	matrix = np.round(matrix, 2)

	xticklabels = []
	yticklabels = []
	for i in range(n):
		xticklabels.append('xticklabel' + str(i))
		yticklabels.append('yticklabel' + str(i))
	
	plot(matrix, xticklabels, yticklabels)

参考:
python如何实现可视化热力图 http://www.php.cn/python-tutorials-391565.html
数据可视化Seaborn从零开始学习教程(二) 颜色调控篇 https://segmentfault.com/a/1190000014966210?utm_source=tag-newest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值