小编Kil*_*.G.的帖子

3D直方图和轮廓图Python

我的matplotlib的contourf函数有问题.我有一个txt数据文件,我从中导入我的数据.我有数据列(pm1和pm2),我正在执行2D直方图.我想将此数据绘制为3D直方图和等高线图,以查看最大值的位置.

这是我的代码:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
rows = np.arange(200,1300,10)

hist, xedges, yedges = np.histogram2d (pm1_n, pm2_n, bins = (rows, rows) )
elements = (len(xedges) - 1) * (len(yedges) - 1)


xpos, ypos = np.meshgrid(xedges[:-1], yedges[:-1])

xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(elements)
dx = 0.1 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()

#####The problem is here#####

#ax.contourf(xpos,ypos,hist)
#ax.bar3d(xpos, ypos, zpos, dx, dy, dz, zsort='average')

plt.show()
Run Code Online (Sandbox Code Playgroud)

我可以绘制3D条形图,但我不能绘制轮廓之一,如果我把hist在contourf功能我得到的错误: Length of x must be number …

python matplotlib histogram contour histogram2d

5
推荐指数
1
解决办法
1184
查看次数

标签 统计

contour ×1

histogram ×1

histogram2d ×1

matplotlib ×1

python ×1