脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python pyheatmap包绘制热力图

python pyheatmap包绘制热力图

2021-04-17 00:37Jepson2017 Python

这篇文章主要为大家详细介绍了python pyheatmap包绘制热力图,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")

获取鼠标位置

?
1
2
3
4
5
6
7
8
9
10
11
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)

读取鼠标点击位置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/d1240673769/article/details/81906075

延伸 · 阅读

精彩推荐