title: How do you fill 2Dhistogram with mean bin value in python
body: <p>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.<br>
  I read the following answers but I could not solve this problem.</p>
  
  <p><a href="https://stackoverflow.com/questions/6163334/binning-data-in-python-with-scipy-numpy">binning data in python with scipy/numpy</a></p>
  
  <p><a href="https://stackoverflow.com/questions/24917685/find-mean-bin-values-using-histogram2d-python">find mean bin values using histogram2d python [duplicate]</a></p>
  
  <p>So far, I created a 2Dscatter plot painted with density for reference.</p>
  
  <p>My code is such:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>The input datas are as follows</p>
  
  <pre><code>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]])
  </code></pre>