在matlab中绘制3d条形图
我在matlab中有一个Nx3矩阵,我想用它制作一个3维条形图,其中X轴和Y轴由矩阵第一列和第二列的值确定,每个条形的高度是矩阵中的第三列,条形的数量由 N 确定
。换句话说,如果“data”是矩阵,则:
data(:, 1) % values of X-axis
data(:, 2) % values of Y-axis
data(:, 3) % values of each Z-axis bar
并且每个 1:length(data) 应该有一个条形
我如何在 MATLAB 中执行此操作?
其次,作为此方法的变体,我怎样才能做同样的事情,但这次将条形图直方图放入每个 X、Y、Z 维度的 N 个箱中?即,不用为每个点绘制一个条形图,而是将数据直方图绘制到每个维度的这些箱中,并为每个箱绘制一个条形图。
非常感谢您的帮助。
I have an Nx3 matrix in matlab 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(:, 1) % values of X-axis
data(:, 2) % values of Y-axis
data(:, 3) % values of each Z-axis bar
and there should be one bar for each 1:length(data)
How can I do this in MATLAB?
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.
thanks very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于您的第一个问题,您可以通过以下方式实现与您的要求类似的效果:
不完全是酒吧,但会产生类似的效果。
要绘制“真实”条形图(例如
bar3
图),我认为您必须使用低级图形函数,例如surface
(由bar3
绘制条形图)。关于你的第二个问题,我不确定我是否理解——如果你计算每个维度的直方图,你最终会得到 4 维数据——每个维度的 bin 位置 + 直方图计数本身。你到底想策划什么?
Regarding your 1st question, you can achieve something similar to your request, by:
Not exactly bars, but produces a similar effect.
To plot 'real' bars (such as the ones
bar3
plots), I think you'll have to use low-level graphics function such assurface
(which is used bybar3
to plot bars).Regarding your 2nd question, I'm not sure I understand --- if you calculate a histogram for each dimension, you end up with 4-dimensional data --- the bin location for each dimension + the hist count itself. What exactly do you want to plot?