def main(): data = make_test_data() # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png")
def example1(): # 加载测试数据 data = load_data_from_file("test_data.txt") # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png")
def example2(): data_1 = load_data_from_file("test_data.txt") data_2 = load_data_from_file("test_data2.txt") hm = HeatMap(data_1) hit_img = hm.clickmap() hm2 = HeatMap(data_2) hit_img2 = hm2.clickmap(base=hit_img, color=(0, 0, 255, 255)) hit_img2.save("hit2.png")
def example1(): # 加载测试数据 data = loadDataFromFile("test_data.txt") # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png")
def example1(): # 加载测试数据 data = loadDataFromFile("test_data.txt") # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png",blackbg=True)
def example1(): # 加载测试数据 data = load_data_from_file("test_data.txt") # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") # hm.heatmap(save_as="heat.png", r=20) # 这儿可以传入 r 参数,指定热图半径,默认 r=10 # hm.heatmap(save_as="heat.png", base="/var/tmp/test_base.png") hm.heatmap(save_as="heat.png")
def generate_heatmap(array, percentile=0.5, sign=''): per = np.percentile(array, 1 - percentile) height, width = array.shape hdata = [] for i in range(height): for j in range(width): if (array[i][j] > per): hdata.append([i, j]) hm = HeatMap(hdata) hm.clickmap(save_as='hit' + str(sign) + '.png') hm.heatmap(save_as='heat' + str(sign) + '.png')
def main(opt): minus = np.array([[0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]]) # Gets all data points, and transformed into (x,y) pos = [] with open(opt.input, 'r') as file: for line in file.readlines(): r, theta = map(lambda x: float(x), line[:-1].split(',')) pos.append([ int(opt.scale * r * math.cos(toPhi(theta))), int(-opt.scale * r * math.sin(toPhi(theta))) ]) pos = np.asarray(pos) minimum = -np.min(pos) pos = pos - np.min(pos) # pos = np.apply_along_axis(lambda l: np.append(l, opt.duplicate), 1, pos) ans = np.copy(pos) if SHIFT: for i in range(minus.shape[0]): ans = np.concatenate( (ans, np.apply_along_axis(lambda l: l - minus[i], 1, pos))) print(ans.shape) hm = HeatMap(ans.tolist()) # ------------ Draw all points ------------ hm.clickmap(save_as=opt.input + "_hit.png") img = hm.heatmap() draw = ImageDraw.Draw(img) unit = 5 font = ImageFont.truetype("/Library/Fonts/Arial.ttf", size=40) for i in range(5): radius = unit * i * opt.scale draw.ellipse((minimum - radius, minimum - radius, minimum + radius, minimum + radius), outline='black') draw.text(toxy((minimum, minimum), radius, 130), "%d\u00B0" % (unit * i), 'black', font=font) halfline = 5 * unit * opt.scale draw.line([(minimum - halfline, minimum), (minimum + halfline, minimum)], fill='black') draw.line([(minimum, minimum - halfline), (minimum, minimum + halfline)], fill='black') img.save(opt.input + "_heat.png") print("Two files generated!")
def main(): # url = "https://raw.github.com/oldj/pyheatmap/master/examples/test_data.txt" ff = open('./test_data.txt', 'r') sdata = ff.read().split("\n") data = [] for ln in sdata: a = ln.split(",") if len(a) != 2: continue a = [int(i) for i in a] data.append(a) # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png")
def main(): data = [] # download test data url = "https://raw.github.com/oldj/pyheatmap/master/examples/test_data.txt" for line in urllib.request.urlopen(url): line_str = str(line, encoding='utf-8').split("\n") for ln in line_str: if ',' in ln: a = ln.split(",") a = [int(i) for i in a] data.append(a) hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png")
def main(srcUrl, clkMap, heatMap, width, height): # url = "https://raw.github.com/oldj/pyheatmap/master/examples/test_data.txt" # sdata = urllib.urlopen(url).read().split("\n") # url = "D:/DEV/GitHub/Sokaris_View3D/Sokaris_View3D/IntersectionsHN.ini" sdata = open(srcUrl, 'r').read().split('\n') data = [] for ln in sdata: a = ln.split(" ") if len(a) != 2: continue a = [int(i) for i in a] data.append(a) hm = HeatMap(data=data,width=width,height=height) hm.clickmap(save_as=clkMap) hm.heatmap(save_as=heatMap)
def main(srcUrl, clkMap, heatMap, width, height): # url = "https://raw.github.com/oldj/pyheatmap/master/examples/test_data.txt" # sdata = urllib.urlopen(url).read().split("\n") # url = "D:/DEV/GitHub/Sokaris_View3D/Sokaris_View3D/IntersectionsHN.ini" sdata = open(srcUrl, 'r').read().split('\n') data = [] for ln in sdata: a = ln.split(" ") if len(a) != 2: continue a = [int(i) for i in a] data.append(a) hm = HeatMap(data=data, width=width, height=height) hm.clickmap(save_as=clkMap) hm.heatmap(save_as=heatMap)
def test(): u"""测试方法""" print("load data..") data = [] f = open("../examples/test_data.txt") for ln in f: a = ln.split(",") if len(a) != 2: continue x, y = int(a[0]), int(a[1]) data.append([x, y]) f.close() print("painting..") # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png") print("done.")
import datetime import function_2 as func_2 import main_1 import matplotlib.pyplot as plt from pyheatmap.heatmap import HeatMap # Get accident location and plot scatter diagram and heat map acc_origin_path = r'C:/Users/lkr/Desktop/graduate/previous_data/accident_2015.csv' # path for address descriptions acc_new_path = r'C:/Users/lkr/Desktop/graduate/previous_data/accident_longitude_latitude.csv' # path for longitudes and latitudes func_2.get_location(acc_origin_path, acc_new_path) acc_location = pd.read_csv( r'C:/Users/lkr/Desktop/graduate/previous_data/accident_longitude_latitude.csv' ) plt.scatter(acc_location, s=20, c='b') # plot scatter diagram hm = HeatMap(acc_location) # plot heat map hm.clickmap(save_as='hit.png') hm.heatmap(save_as='heat.png') # Accidents-Sample points match sp_location = pd.read_csv( r'C:/Users/lkr/Desktop/graduate/previous_data/sample_points_location.csv') sp_match = [] for i in acc_location: dist = 99999 sp = [-1, -1] for j in sp_location: if dist > func_2.mhd_distance(i, j) > 0.001: dist = func_2.mhd_distance(i, j) sp = j sp_match = [sp_match, sp] sp_match = pd.DataFrame(sp_match)
from pyheatmap.heatmap import HeatMap from PIL import Image import csv import math data=[] minx = 0 miny = 0 basewidth = 500 with open('test.csv', newline = '') as csvfile: reader = csv.reader(csvfile, delimiter = ' ', quotechar = '|') for row in reader: sp = row[0].split(",") r = float(sp[0]) t = float(sp[1]) x = int(r*math.cos(t)) y = int(r*math.sin(t)) minx = min(x, minx) miny = min(y, miny) print(minx, miny) data.append([x - minx, y - miny]) hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png") im = Image.open("heat.png") im = im.rotate(270) print(im.format, im.size, im.mode) im.save("heat_resize.png", "PNG")
import matplotlib.pyplot as plt # file=np.load('COCO_train2014_000000001580.npy','r') file = np.load('COCO_train2014_000000014537.npy', 'r') # file=np.load('COCO_val2014_000000000294.npy','r') f = [] for i in range(640): s = [] for j in range(502): s.append(file[i][j][6]) f.append(s) hm = HeatMap(f) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png") def apply_heatmap(image, data): '''image是原图,data是坐标''' '''创建一个新的与原图大小一致的图像,color为0背景为黑色。这里这样做是因为在绘制热力图的时候如果不选择背景图,画出来的图与原图大小不一致(根据点的坐标来的),导致无法对热力图和原图进行加权叠加,因此,这里我新建了一张背景图。''' background = Image.new("RGB", (image.shape[1], image.shape[0]), color=0) # 开始绘制热度图 hm = HeatMap(data) hit_img = hm.heatmap(base=background, r=100) # background为背景图片,r是半径,默认为10 # ~ plt.figure() # ~ plt.imshow(hit_img) # ~ plt.show() #hit_img.save('out_' + image_name + '.jpeg') hit_img = cv2.cvtColor(np.asarray(hit_img),