3D条形图增加了Bar的正方形区域

时间:2014-06-27 22:50:07

标签: python matplotlib 3d

我从分布中得到以下代码图,然后绘制与bin中频率对应的3d直方图。

# Given a data array of x and y such that they correspond
# to a number of points, this draws a 3d Bar Graph corresponding
# to density of points.
def hist_3dBar(x,y,bins):
    fig = plt.figure()
    ax = Axes3D(fig)
    hist, xedges, yedges = np.histogram2d(x,y,bins)
    elements = (len(xedges) - 1) * (len(yedges) - 1)
    xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25)
    xpos = xpos.flatten()
    ypos = ypos.flatten()
    zpos = np.zeros(elements)
    dx = np.ones_like(zpos)
    dy = dx.copy()
    dz = hist.flatten()
    ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
    return fig

使用代码调用它:

# Produce a number of points in x-y from another distribution.
mean = [0,0]
cov = [[3,2],[2,3]] 
xp,yp = np.random.multivariate_normal(mean,cov,1000).T
plt.plot(xp,yp,'o'); plt.axis('equal'); plt.show()
hist_3d = gauss.hist_3dBar(x,y,10)

我只是想让条纹彼此相邻,底部没有空格。另外,如何根据bin中的频率获取颜色代码?

谢谢!

0 个答案:

没有答案