数据格式如下:

8_15/l_eye/2732.png -20.5773 -5.17769 -3.34583 21.5859
9_13_1/l_eye/1211.png -10.1145 34.9928 -38.2122 -26.3371
8_20/l_eye/5966.png -44.0264 50.2898 63.5838 -49.1353
8_13/l_eye/8780.png -16.9358 50.4528 -44.2617 -57.1462
9_16_2/l_eye/5370.png -21.2264 17.0589 4.33619 -20.3562
9_15_1/l_eye/66.png 40.5758 -21.0923 12.0032 40.8452
8_13/l_eye/6664.png 51.0789 55.3987 -67.2433 -79.1243
9_15_2/l_eye/4429.png 16.958 30.0386 -24.5935 -26.4802
8_21/l_eye/2579.png -20.619 4.7845 21.9891 27.529
8_21/l_eye/8464.png -36.8559 54.4664 -32.1576 -67.6335
8_21/l_eye/359.png 20.9732 2.25414 -3.88966 41.175
9_16_2/l_eye/3065.png 7.16623 43.091 35.9651 -28.4994
9_14_2/l_eye/1961.png 33.3302 28.3553 22.7904 -28.5209
9_16_1/l_eye/2038.png 56.9721 24.6518 -23.5831 -39.2209

以2、3列为x、y绘制一个热力图

以4、5列为x、y绘制一个热力图

#!/usr/bin/python
# -*- encoding: utf-8 -*- import numpy as np
from matplotlib import pyplot as plt #import thread
#from threading import Thread
from multiprocessing import Process import pdb def generate_heat_array(is_test=0):
#pdb.set_trace()
if is_test==1:
# gussian distribution
mean = [0,0]
cov = [[0,1],[1,0]]
x, y = np.random.multivariate_normal(mean, cov, 10000).T
show_heat_map(x,y)
return x_head=[]
y_head=[]
x_gaze=[]
y_gaze=[]
for line in open('train.txt'):
split_data=line.split()
x_head.append(float(split_data[1]))
y_head.append(float(split_data[2]))
x_gaze.append(float(split_data[3]))
y_gaze.append(float(split_data[4])) #用thread库实现多线程
#由于主线程退出时,子线程自动中止,因此需要join;由于thread库未提供join方法,所以需要自己手动实现。
#thread.start_new_thread(show_heat_map,(x_head,y_head,1))
#thread.start_new_thread(show_heat_map,(x_gaze,y_gaze,2)) #用threading库实现多线程
#threading库提供了join方法。但是由于matplotlib.pyplot中的方法都是全局的,因此用多线程绘图会有错误:RuntimeError: main thread is not in main loop
#head_thread=Thread(target=show_heat_map, args=(x_head,y_head,1,))
#gaze_thread=Thread(target=show_heat_map,args=(x_gaze,y_gaze,2,))
#head_thread.start()
#gaze_thread.start()
#head_thread.join()
#gaze_thread.join() #用multiprocessing实现多进程
head_process=Process(target=show_heat_map,args=(x_head,y_head,1,))
gaze_process=Process(target=show_heat_map,args=(x_gaze,y_gaze,2,))
head_process.start()
gaze_process.start()
head_process.join()
gaze_process.join() def show_heat_map(x,y,n):
#pdb.set_trace()
fig=plt.figure(n)
plt.hist2d(x,y,bins=100)
plt.grid(True)
plt.colorbar()
#fig.savefig('%02i.png'%n)
plt.show() if __name__=='__main__':
generate_heat_array(0)

绘制热力图的方法:

    plt.hist2d(x,y,bins=100)

x为横轴的值的list,y为纵轴值的list

修改bins可以控制区间大小

参考:http://blog.topspeedsnail.com/archives/707

使用meshgrid+imshow的话横纵坐标会有问题

多进程使用matplotlib.pyplot绘heatmap(多线程不可以)的更多相关文章

  1. Matplotlib.pyplot 常用方法

    1.介绍 Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过 Matplotlib,开发者可以仅需要几行代码,便可以生成绘图 ...

  2. matplotlib.pyplot 导引

    matplotlib.pyplot 是采用 python 语言和使用数值数学库 numpy 数组数据的绘图库.其主要目标是用于数据的可视化显示. 输出图形组成 matplotlib.pyplot 模块 ...

  3. matplotlib.pyplot 绘图详解 matplotlib 安装

    apt-get install python-matplotlib 转载自: http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086. ...

  4. matplotlib.pyplot.hist

    **n, bins, patches = plt.hist(datasets, bins, normed=False, facecolor=None, alpha=None)** ## 函数说明 用于 ...

  5. 数据分析之matplotlib.pyplot模块

    首先都得导模块. import numpy as np import pandas as pd import matplotlib.pyplot as plt from pandas import S ...

  6. Python Matplotlib.pyplot plt 中文显示

    话不多说,上代码 # -*- coding: UTF-8 -*- import matplotlib.pyplot as plt from matplotlib.font_manager import ...

  7. 在绘图的时候import matplotlib.pyplot as plt报错:ImportError: No module named '_tkinter', please install the python-tk package

    在绘图的时候import matplotlib.pyplot as plt报错:ImportError: No module named '_tkinter', please install the ...

  8. Matplotlib.pyplot 把画图保存为图片

    在plt.show()之前执行plt.savefig()函数即可. 简单例子: import matplotlib.pyplot as plt x=[1,2,3,4,5] y=[10,5,15,10, ...

  9. 使用numpy与matplotlib.pyplot画图

    使用numpy与matplotlib.pyplot画图 1. 折线图 1 # -*- enccoding:utf-8 -*- 2 import numpy as np 3 import matplot ...

随机推荐

  1. JS - caller,callee,call,apply

    在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments : 该对象代表正在执行的函数和调用它的函数的参数. [function.]argument ...

  2. nginx+keeplived负载均衡配置

    一.nginx 编译安装 1.依赖环境安装     yum -y install gcc gcc-c++ zlib zlib-devel pcre pcre-devel openssl openssl ...

  3. Ubuntu 下添加OpenERP command 快捷启动方式

    编辑home目录下的.bashrc文件 alias xjerp="~/odoo/xj/openerp-server -r openerp --addons-path='~/odoo/xj/o ...

  4. Hive及HBase数据迁移

    一. Hive数据迁移 场景:两个Hadoop平台集群之间Hive表迁移. 基本思路:Hive表元数据和文件数据export到HDFS文件,通过Distcp将HDFS迁移到另一个集群的HDFS文件,再 ...

  5. php json包 Services_JSON-1.0.2 1 ---one

  6. ubuntu vnc安装

    VNC(Virtual Network Computing),为一种使用RFB协议的屏幕画面分享及远程操作软件.此软件借由网络,可发送键盘与鼠标的动作及即时的屏幕画面. 1. 安装vnc服务器 sud ...

  7. java----内部类与匿名内部类的各种注意事项与知识点

    Java 内部类分四种:成员内部类.局部内部类.静态内部类和匿名内部类.1.成员内部类: 即作为外部类的一个成员存在,与外部类的属性.方法并列.注意:成员内部类中不能定义静态变量,但可以访问外部类的所 ...

  8. 多线程编程(三)--创建线程之Thread VS Runnable

    前面写过一篇基础的创建多线程的博文: 那么本篇博文主要来对照一下这两种创建线程的差别. 继承Thread类: 还拿上篇博客的样例来说: 四个线程各自卖各自的票,说明四个线程之间没有共享,是独立的线程. ...

  9. Centos查看系统位数方法

    方法一:file /sbin/init 方法二:file /bin/ls 我的显示是32位

  10. iphone中点击input不能选中input中的内容

    点击一个input,通过它的click事件选中这个input框中的内容,这个用jquery挺好实现的,但是有一个问题,在PC端和android手机上都可以让功能正常实现,在iphone上就没有效果了, ...