我的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 …