如何在hist2d(matplotlib)中设置bin内容

2024-04-25 22:33:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在(x,y)中绘制z binned的值。这看起来像matplotlib中的hist2d,但是bin内容由另一个数组定义,而不是表示计数的数量。有没有办法在hist2d中设置bin内容?在


Tags: 内容数量bin定义matplotlib绘制数组计数
2条回答

是否要设置每个箱子中的元素数?我认为这是条形图而不是柱状图。所以只需使用ax.bar就可以了。在

编辑tcaswell的好观点,对于多维图像,等价物是imshow,而不是bar。在

不,在hist2d中无法设置bin内容,但有两个可选选项。在

1)可以使用bar3d手动定义每个bin的边界,但它并不总是很好地渲染。在

hist,xbinedges,ybinedges = np.histogram2d(x,y,bins=bins,range=range)
BinlowEdgex, BinlowEdgey = np.meshgrid(xbinedges[:-1], ybinedges[:-1])
xbinwidth = ((range[0][1]-range[0][0])/(bins[0]))
ybinwidth = ((range[1][1]-range[1][0])/(bins[1]))
ax.bar3d(BinlowEdgex.flatten(), BinlowEdgey.flatten(), np.zeros(bins[0]*bins[1]), xbinwidth*np.ones(bins[0]*bins[1]), ybinwidth*np.ones(bins[0]*bins[1]), zvalues.flatten())

2)你可以放弃3d直方图的想法,用颜色来表示Z值。在

^{pr2}$

相关问题 更多 >