5 つのポイント (x、y) があり、matplotlib の histogram2d 関数を使用して、各ビンの密度を示すさまざまな色を示すヒートマップを作成しました。ビン内のポイント数の頻度を取得するにはどうすればよいですか?
import numpy as np
import numpy.random
import pylab as pl
import matplotlib.pyplot as plt
x = [.3, -.3, -.3, .3, .3]
y = [.3, .3, -.3, -.3, -.4]
heatmap, xedges, yedges = np.histogram2d(x, y, bins=4)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.clf()
plt.imshow(heatmap, extent=extent)
plt.show()
pl.scatter(x,y)
pl.show()
したがって、4 つのビンを使用すると、各ビンの頻度は .2、.2、.2、および .4 になると予想されます。