python画矩阵热图_如何在Python中创建热图矩阵并生成基于“热”的区域?

Given a set of points (x, y, 'heat'),

In [15]: df.head()

Out[15]:

x y heat

0 0.660055 0.395942 2.368304

1 0.126268 0.187978 6.760261

2 0.174857 0.637188 1.025078

3 0.460085 0.759171 2.635334

4 0.689242 0.173868 4.845778

How to generate a heat map matrix and delimit heat regions (hard)?

in such a way that, given a point, it is possible to get all points within the same region.

PS:

From Generate a heatmap in MatPlotLib using a scatter data set, I know how to generate graphs of regions, but not how to generate the region 'matrix' (so that given a property, it says in which region it is).

解决方案

I guess it depend how you did the heatmap but assuming you used the first example from the post you linked:

import numpy as np

import numpy.random

import matplotlib.pyplot as plt

# Generate some test data

x = np.random.randn(8873)

y = np.random.randn(8873)

heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)

extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

plt.clf()

plt.imshow(heatmap, extent=extent)

plt.show()

So you now if you have a request about a point with coords (a,b) you need to find the position of the nearest value to a in xedges (lets call it a_heatmap), the position of the nearest value of b in yedges (b_heatmap), then look for the returned value by :

heatmap[a_heatmap, b_heatmap]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值