问题
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