I would like to use binned_statistic_2d (from scipy) on my dataset, but with custom bin edges calculated so that in every bin there is an equal number of points.
I tried to modify code from user farenorth for 2d dataset, but I'm beginner in python, and have trouble with it. That code (1d) is:
def histedges_equalN(x, nbin):
npt = len(x)
return np.interp(np.linspace(0, npt, nbin + 1),
np.arange(npt),
np.sort(x))
x = np.random.randn(100)
n, bins, patches = plt.hist(x, histedges_equalN(x, 10))
I just need it modified for 2d histogram. Can you show me how it's done?