matplotlib热图
1.基础知识点回顾
- 1.plot(x, y, marker='D')表示绘制折线图,marker设置样式菱形。
- 2.scatter(x, y, marker='s', color='r')绘制散点图,红色正方形。
- 3.bar(x, y, 0.5, color='c')绘制柱状图,间距为0.5,原色。
- 4.hist(data,40,normed=1,histtype='bar',facecolor='yellowgreen',alpha=0.75)直方图。
- 5.设置x轴和y轴的坐标值:
- xlim(-2.5, 2.5) #设置x轴范围
- ylim(-1, 1) #设置y轴范围
- 6.显示中文和负号代码如下:
- plt.rcParams['font.sas-serig']=['SimHei'] #用来正常显示中文标签
- plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
2.Heatmap热图基础知识
详情请参阅:http://matplotlib.org/users/image_tutorial.html
In [1]: import matplot.pyplot as plt
In [2]: help(plt.imshow)
Help on function imshow in module matplotlib.pyplot:
imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, hold=None, data=None, **kwargs)
Display an image on the axes.
Parameters
----------
X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4)
Display the image in `X` to current axes. `X` may be an
array or a PIL image. If `X` is an array, it
can have the following shapes and types:
- MxN -- values to be mapped (float or int)
- MxNx3 -- RGB (float or uint8)
- MxNx4 -- RGBA (float or uint8)
The value for each component of MxNx3 and MxNx4 float arrays
should be in the range 0.0 to 1.0. MxN arrays are mapped
to colors based on the `norm` (mapping scalar to scalar)
and the `cmap` (mapping the normed scalar to a color).
cmap : `~matplotlib.colors.Colormap`, optional, default: None
If None, default to rc `image.cmap` value. `cmap` is ignored
if `X` is 3-D, directly specifying RGB(A) values.
参数X可以是图片也可以数组,若是数组,必须以下三种形式
- MxN:values to be mapped (float or int)
- MxNx3 -- RGB (float or uint8)
- MxNx4 -- RGBA (float or uint8))
- 3维数组或4维数组范围必须是(0,1)
- 参考:http://blog.csdn.net/Eastmount/article/details/73392106?fps=1&locationNum=5
3.Heatmap热图绘制

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
from matplotlib import axes
def draw_heatmap(data,xlabels,ylabels):
#cmap=cm.Blues
cmap=cm.get_cmap('rainbow',1000)
figure=plt.figure(facecolor='w')
ax=figure.add_subplot(1,1,1,position=[0.1,0.15,0.8,0.8])
ax.set_yticks(range(len(ylabels)))
ax.set_yticklabels(ylabels)
ax.set_xticks(range(len(xlabels)))
ax.set_xticklabels(xlabels)
map=ax.imshow(data,interpolation='nearest',cmap=cmap,aspect='auto',vmin=a.min(),vmax=a.max())
cb=plt.colorbar(mappable=map,cax=None,ax=None,shrink=0.5)
plt.show()
a=np.random.rand(10,10)
print(a)
xlabels=['A','B','C','D','E','F','G','H','I','J']
ylabels=['a','b','c','d','e','f','g','h','i','j']
draw_heatmap(a,xlabels,ylabels)
这里想把某块显示成一种颜色,则需要调用interpolation='nearest'参数即可
matplotlib热图的更多相关文章
- 基于matplotlib的数据可视化 - 热图imshow
热图: Display an image on the axes. 可以用来比较两个矩阵的相似程度 mp.imshow(z, cmap=颜色映射,origin=垂直轴向) imshow( X, cma ...
- Matplotlib学习---用matplotlib画热图(heatmap)
这里利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://datasets.flowingdata.com/ppg2008.csv ...
- python matplotlib imshow热图坐标替换/映射
今天遇到了这样一个问题,使用matplotlib绘制热图数组中横纵坐标自然是图片的像素排列顺序, 但是这样带来的问题就是画出来的x,y轴中坐标点的数据任然是x,y在数组中的下标, 实际中我们可能期望坐 ...
- Python图表数据可视化Seaborn:3. 线性关系数据| 时间线图表| 热图
1. 线性关系数据可视化 lmplot( ) import numpy as np import pandas as pd import matplotlib.pyplot as plt import ...
- 基于HTML5实现3D热图Heatmap应用
Heatmap热图通过众多数据点信息,汇聚成直观可视化颜色效果,热图已广泛被应用于气象预报.医疗成像.机房温度监控等行业,甚至应用于竞技体育领域的数据分析. http://www.hightopo.c ...
- 用Excel制作热图(heatmap)的方法
http://jingyan.baidu.com/article/64d05a0240ec75de55f73bd8.html 利用Excel 2010及以上版本的"条件格式"--& ...
- Heatmap.js v2.0 – 最强大的 Web 动态热图
Heatmap 是用来呈现一定区域内的统计度量,最常见的网站访问热力图就是以特殊高亮的形式显示访客热衷的页面区域和访客所在的地理区域的图示.Heatmap.js 这个 JavaScript 库可以实现 ...
- 基于HTML5实现的Heatmap热图3D应用
Heatmap热图通过众多数据点信息,汇聚成直观可视化颜色效果,热图已广泛被应用于气象预报.医疗成像.机房温度监控等行业,甚至应用于竞技体育领域的数据分析. 已有众多文章分享了生成Heatmap热图原 ...
- matplotlib 出图示例
如果你想要在Linxu中获得一个高效.自动化.高质量的科学画图的解决方案,应该考虑尝试下matplotlib库.Matplotlib是基于python的开源科学测绘包,基于python软件基金会许可证 ...
随机推荐
- maven mvn Failed during checkstyle execution
maven 命令默认强制使用checkstyle, 造成 命令运行失败 并报错: Failed during checkstyle execution 关闭checkstyle,命令如下: mvn [ ...
- vue路由使用踩坑点:当动态路由再使用路由name去匹配跳转时总是跳转到根路由的问题
闲话少说,直接问题: 之前我的路由时这么写的 { path:'/serverInfo/:id', name:'serverInfo', component:() => import('@/vie ...
- Golang 中错误与异常需要重新认识
如何进行错误处理,这是一个Go程序员之间,特别是一些新的Go程序员,会经常讨论的问题.讨论到最后往往由于以下代码的多次出现而变成了抱怨. if err != nil { return err } 我们 ...
- Spark Streaming updateStateByKey案例实战和内幕源码解密
本节课程主要分二个部分: 一.Spark Streaming updateStateByKey案例实战二.Spark Streaming updateStateByKey源码解密 第一部分: upda ...
- Java方法重写与方法重载
方法重载:发生在同一个类中,方法名相同方法形参列表不同就会重载方法. 方法重写:发生在继承当中,如果子的一个类方法与父类中的那个方法一模一样(方法名和形参列表一样),那么子类就会重写父类的方法. 方法 ...
- [Android] Content provider, ContentResolver
Content provider的作用: Content providers manage access to a structured set of data. They encapsulate t ...
- VM虚拟机启动报错Reason Failed to lock the file怎么办
VMware启动报错Reason: Failed to lock the file的解决方法 症状: 启动VMware虚拟机的时候出现了Cannot open the disk '*.vmdk' o ...
- redis 配置步骤
1.下载 2.启动 3.持久化(快照和AOF) 4.主从配置(集群) 5.读写分离 6.自动切换主从 7.哨兵服务(集群) 8.集群锁 9.Session共享
- ZH奶酪:Ubuntu客户端通过SSH方式远程登录Ubuntu服务器
1.概述 传统的远程登录(telnet,rlogin)时不安全的,他们在网络上用明文传输口令和数据,SSH则是安全的,openssh提供两种级别的验证方式. (1)基于口令的安全验证:知道服务器的帐号 ...
- SqlServer日常积累(三)
1.TRUNCATE 和 DELETE TRUNCATE操作没有记录删除操作日志 主要的原因是因为 TRUNCATE 操作不会激活触发器,因为TRUNCATE操作不会记录各行删除操作的日志,所以当你需 ...