Python 三维条形图增加条形图的平方面积
我从一个分布中绘制了以下代码,然后绘制了与bin中的频率对应的3d直方图Python 三维条形图增加条形图的平方面积,python,matplotlib,3d,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(f
# 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)
我只是想让这些条彼此相邻,底部没有空格。另外,如何根据箱子中的频率获取颜色代码
谢谢