绘制 3D 直方图/条形图
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵第一列和第二列的值以及每个条形的高度确定是矩阵中的第三列,条形的数量由 N 确定
。换句话说,如果“data”是矩阵,则:
data[:, 0] # values of X-axis
data[:, 1] # values of Y-axis
data[:, 2] # values of each Z-axis bar
并且每个 len(data) 应该有一个条形
我如何在 Matplotlib 中执行此操作?
其次,作为此方法的变体,我怎样才能做同样的事情,但这次将条形图直方图放入每个 X、Y、Z 维度的 N 个箱中?即,不用为每个点绘制一个条形图,而是将数据直方图绘制到每个维度的这些箱中,并为每个箱绘制一个条形图。
I have an Nx3 matrix in scipy/numpy and I'd like to make a 3 dimensional bar graph out of it, where the X and Y axes are determined by the values of first and second columns of the matrix, the height of each bar is the third column in the matrix, and the number of bars is determined by N.
In other words, if "data" is the matrix then:
data[:, 0] # values of X-axis
data[:, 1] # values of Y-axis
data[:, 2] # values of each Z-axis bar
and there should be one bar for each len(data)
How can I do this in Matplotlib?
Secondly, as a variant of this, how can I do the same thing, but this time histogram the bars into N bins in each X, Y, Z dimension? I.e. instead of a bar for each point, just histogram the data into those bins in every dimension, and plot a bar for each bin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在根据示例正确塑造数据的“高度”方面遇到了一些困难,但最终让它与以下代码一起使用。这里,Z 是一个包含我所有数据的 3 维数组,x 和 rval 基本上是与数据点相对应的二维索引。
I had a little of a hard time shaping the 'heights' of my data properly from the examples, but finally got it to work with the following code. Here, Z is a 3 dimensional array with all of my data, and x and rval are basically the 2-d indices corresponding to the datapoints.