you're using 4x4 = 16 bins. If you want four total bins, use 2x2:
In [45]: np.histogram2d(x, y, bins=2)
Out[45]:
(array([[ 1., 1.],
[ 2., 1.]]),
array([-0.3, 0. , 0.3]),
array([-0.4 , -0.05, 0.3 ]))
You can specify the full shape of the output with a tuple: bins=(2,2)
If you want to normalize the output, use normed=True
:
In [50]: np.histogram2d(x, y, bins=2, normed=True)
Out[50]:
(array([[ 1.9047619 , 1.9047619 ],
[ 3.80952381, 1.9047619 ]]),
array([-0.3, 0. , 0.3]),
array([-0.4 , -0.05, 0.3 ]))