具有3个变量的numpy直方图 [英] numpy histogram with 3 variables

查看:226
本文介绍了具有3个变量的numpy直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个重复的问题,请原谅我,我已尽力寻找解决方案.这似乎非常简单,但我似乎找不到任何适用的方法.

Please forgive me if this is a repeated question, I've done my best to look for a solution. This seems very straightforward but I can't seem to find anything applicable.

我正在尝试使用3个1D numpy数组中的数据生成图(如热图).数据的基本安排如下:

I'm trying to generate a plot (like a heatmap) using data from 3 1-D numpy arrays. The data is basically arranged as follows:

x_axis = ([1, 4, 6])
y_axis = ([2, 5, 7])
z_axis = ([5, 8, 9])

(我的数据集实际上更大,有时成千上万个条目).

(my data sets are actually much larger... sometimes hundreds of thousands of entries).

所以我有z_axis值,每个值都与x坐标和y坐标关联...例如,点(1,2)的值与5关联.

so I've got z_axis values that are each associated with an x-coordinate and y-coordinate... for example, the point (1,2) has the value 5 associated with it.

我要做的就是以这种方式绘制该图,以便将z值平均化为我指定的任何bin大小,并像热图一样进行颜色编码.因此,例如,如果我有10个数据点落在给定的bin中,则它们的z值将被平均,并且该值将落在色谱的某个地方.

All I want to do is plot this in such a way that the z values are averaged out for whatever bin size I specify, and color-coded like a heatmap. So, for instance, if I've got 10 data points that fall within a given bin, their z-values will be averaged and that value will fall somewhere on a color spectrum.

感谢您可以提供的任何帮助.

Thanks for any help you can provide.

推荐答案

来自装箱数很容易更改.

如杰米(Jamie)在评论中所指出的,如果您想要每个仓位中点的平均值:

As Jamie pointed out in the comments if you want the average of the points in each bin:

numbins=10
H, xedges, yedges =np.histogram2d(x_axis, y_axis, bins=numbins, weights=z_axis) 
count, x, y =np.histogram2d(x_axis, y_axis, bins=numbins) 
H/=count

这篇关于具有3个变量的numpy直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆