I have density ranges for the x and y axis and I am trying to make 2D histogram that is painted with mean values in each bins for the respective density instead of counts.
I read the following answers but I could not solve this problem.
binning data in python with scipy/numpy
find mean bin values using histogram2d python [duplicate]
So far, I created a 2Dscatter plot painted with density for reference.
My code is such:
x=np.array(data['orb_x'])
y=np.array(data['orb_y'])
dens=np.array(data['dens'])
fig=plt.figure(figsize=(4, 4))
ax=fig.add_subplot(111)
plt.scatter(x,y,c=dens,cmap=cm.jet, marker='.',lw=0,norm=mpl.colors.LogNorm())
plt.xlabel('x')
plt.ylabel('y')
cbar=plt.colorbar()
mpl.colorbar.ColorbarBase.set_label(cbar,"density")
plt.axis('equal')
plt.show()
The input datas are as follows
In [2]: x=np.array(data['orb_x'])
...: y=np.array(data['orb_y'])
...: dens=np.array(data['dens'])
...: np.c_[x, y,dens]
...:
Out[2]:
array([[ 1.20073987e-01, -8.44898256e+00, 4.49877634e-03],
[ 1.22193104e-01, -8.44608810e+00, 5.50857828e-03],
[ 1.24312219e-01, -8.44319365e+00, 2.45374284e-02],
...,
[ 6.57238518e-02, -8.34309436e+00, 4.14459952e-03],
[ 6.78891550e-02, -8.34015383e+00, 3.30193122e-03],
[ 7.00544584e-02, -8.33721330e+00, 8.65938299e-03]])