python pyheatmap包绘制热力图

yipeiwu_com5年前Python基础

利用python pyheatmap包绘制热力图,供大家参考,具体内容如下

import matplotlib.pyplot as plt
from pyheatmap.heatmap import HeatMap

def plot_data(filename):
 with open(filename,'r') as fh:
  data=fh.read().split('\n')
 xs = []
 ys = []
 data_test=[]
 for line in data:
  line=line.strip().split()
  if len(line)>3:
   opt, x, y = line[0], line[1], line[2]
   if opt == '0':
    xs.append(int(x))
    ys.append(int(y))
    data_test.append([int(x),int(y)])

 plt.xlim()
 plt.ylim()
 plt.xlabel("x")
 plt.ylabel("y")
 plt.plot(xs, ys, 'ro')
 plt.show()
 return data_test


filename='track.log'
data=plot_data(filename) 

# 开始绘制
hm = HeatMap(data)
hm.clickmap(save_as="hit.png")
hm.heatmap(save_as="heat.png")

# 绘制带背景的点击热图
hm2 = HeatMap(data)
hit_img2 = hm2.clickmap(base='base.png') # base.png为背景图片
hit_img2.save("hit2.png")

获取鼠标位置

import time
import pyautogui as pag


while True:
 #print("Press Ctrl-C to end")
 screenWidth, screenHeight = pag.size() #获取屏幕的尺寸
 #print(screenWidth,screenHeight)
 x,y = pag.position() #获取当前鼠标的位置
 print(x,y)
 time.sleep(0.1)


读取鼠标点击位置

import pythoncom, pyHook
def onMouseEvent(event):
  print("Position:", event.Position)
  return True
def main():
 hm = pyHook.HookManager()
 hm.HookKeyboard()
 hm.MouseAllButtonsDown = onMouseEvent
 hm.MouseAllButtonsUp = onMouseEvent
 hm.HookMouse()
 pythoncom.PumpMessages()
if __name__ == "__main__":
 main()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

使用django的objects.filter()方法匹配多个关键字的方法

介绍: 今天在使用django的时候忽然想用到,如何匹配多个关键字的操作,我们知道django有一个objects.filter()方法,我们可以通过如下一句代码实现匹配数据库中titl...

详解Python绘图Turtle库

详解Python绘图Turtle库

 Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面...

从请求到响应过程中django都做了哪些处理

前言 最近面试的时候,被面试官问道一个问题,就是 request.user 里面的 user 是怎样得到的,这个问题当时没有回答上来,可以说是非常的尴尬,所以赶快查了一些资料,看了一些源...

Python计算一个文件里字数的方法

本文实例讲述了Python计算一个文件里字数的方法。分享给大家供大家参考。具体如下: 这段程序从所给文件中找出字数来。 from string import * def countW...

基于Python的PIL库学习详解

摘要 对于图像识别,大量的工作在于图像的处理,处理效果好,那么才能很好地识别,因此,良好的图像处理是识别的基础。在Python中,有一个优秀的图像处理框架,就是PIL库,本博文会分模块...