2

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]])
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
sam
  • 63
  • 4
  • can you share some input data? – Tiny.D May 28 '17 at 04:16
  • @Tiny.D I added input data. – sam May 28 '17 at 08:34
  • 1
    It's not clear what the plot should represent in terms of the given data. Is the `'dens'` column already the calculated density at some given points? In that case you would want to interpolate the data on a grid, or use a `tripcolor` or `tricontour` plot. If not, what should the final plot be showing? – ImportanceOfBeingErnest May 28 '17 at 09:20
  • 'dens' column is already detected density at some points. I'm going to use tripcolor plot. Thanks you. – sam May 30 '17 at 02:19

0 Answers0