2D histogram coloured by standard deviation in each bin

微笑、不失礼 提交于 2019-12-11 17:09:47

问题


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?

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

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/54092945/2d-histogram-coloured-by-standard-deviation-in-each-bin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!