如何在python中使用平均bin值填充2Dhistogram

时间:2017-05-28 04:06:44

标签: python numpy matplotlib scipy

我有x和y轴的密度范围,我正在尝试制作2D直方图,在每个分档中绘制相应密度的平均值,而不是计数。
我阅读了以下答案,但我无法解决这个问题。

binning data in python with scipy/numpy

find mean bin values using histogram2d python [duplicate]

到目前为止,我创建了一个用密度绘制的2D散点图作为参考。

我的代码就是这样:

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()

输入数据如下

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]])

0 个答案:

没有答案