每个分箱中的2D直方图由标准偏差着色 [英] 2D histogram coloured by standard deviation in each bin

查看:119
本文介绍了每个分箱中的2D直方图由标准偏差着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,有没有一种创建2D直方图的方法,其中每个bin的颜色是通过每个bin中点的标准偏差而不是点密度来着色的?

Is there a way to create a 2D histogram, in Python, where each bin is coloured by standard deviation of points in each bin rather than by point density?

例如,我有一组2D数据,其外观如下:

For example, I have a set of 2D data that looks as follows:

但是我想将其转换为2D直方图,我希望纯度在类似梯度的结构中间会降低.

But I'd like to turn this into a 2D histogram where I expect the purity to decrease in the middle of the gradient-like structure.

我意识到这个问题没有代码,但是如果我能为正确的方向指出这一点,我将不胜感激.也许已经有一种优化的方法可以做到这一点,而且我可以节省时间,而不必创建矩阵或网格并显式计算标准偏差?

I realise there's no code in this question but if I could be pointed in the right direction to do this efficiently I's be very grateful. Perhaps there is an optimised way to do this already and I could save time rather than creating a matrix or mesh and calculating the standard deviation explicitly?

推荐答案

看看scipy.stats.binned_statistic_2d,然后将函数"std"作为"statistic"参数.

Take a look at scipy.stats.binned_statistic_2d, then give the function 'std' as the 'statistic' argument.

该文档似乎以某种方式忽略了"std"的可能性,但是在源代码中它是可用的.否则,您可以给numpy.std作为参数.

The documentation somehow seems to leave out the 'std' possibility but in the source code it is available. Otherwise you could give numpy.std as an argument.

这篇关于每个分箱中的2D直方图由标准偏差着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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