当前位置: 移动技术网 > IT编程>脚本编程>Python > python pyheatmap包绘制热力图

python pyheatmap包绘制热力图

2018年11月26日  | 移动技术网IT编程  | 我要评论

拜见婆婆大人1,重庆环艺电影院,多美娅

利用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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网