python三维图形等高线_三维直方图和等高线图Python

我对matplotlib的contourf函数有问题。我有一个txt数据文件,从中导入数据。我有数据列(pm1和pm2),我正在执行一个二维直方图。我想把这些数据绘制成三维直方图和等高线图,看看最大值在哪里。在

这是我的代码: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()

我可以绘制三维条形图,但是我不能绘制轮廓图,如果我把hist放在courtorf函数中,我会得到错误:Length of x must be number of columns in z,如果我把dz我得到Input z must be a 2D array

我也尝试过使用xedges和yexges,但这并不能解决问题。在

我认为这个问题与函数histogram2D的返回形状有关,但我不知道如何解决它。在

我还想执行一个三维条形图与色码变化从最小值到最大值。有什么办法做这个吗?在

谢谢你

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值