在 Matlab 中的网格上绘制 3D 条形图 [英] Plotting 3D bars over a grid in Matlab

查看:19
本文介绍了在 Matlab 中的网格上绘制 3D 条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个矩阵 A,它包含 50 行和 4 列,并且条目用整数填充.我的兴趣是根据这些数据构建一个堆叠的 3D 条形图.但是,使用 bar3(A,'stacked') 创建一行 50 个条形,而我希望将条形绘制在大小为 5(垂直)x 10(水平)的网格的坐标处.因此,该行中的第一个柱将位于位置 (1,1),第二个柱位于 (1,2),第 11 个柱位于 (2,1),依此类推,直到第 50 个柱位于 (5,10).我似乎无法在 Matlab 中找到这样做的方法,这可能吗?

I have a matrix, A, that contains 50 rows and 4 columns, and the entries are filled with integers. My interest is to construct a stacked 3D bar plot from this data. However, using bar3(A,'stacked') creates a row of 50 bars, whereas I want the bars to be plotted at the coordinates of a grid of size 5 (vertical) x 10 (horizontal). So the first bar in the row would be at location (1,1), second bar at (1,2), 11th bar at (2,1) and so on until the 50th bar which would be at (5,10). I can't seem to find a way to do this in Matlab, is this possible at all?

提前谢谢你!

推荐答案

我同意@cris,有更好的方法来表示您的数据.但是,如果您仍想使用 3D 条形图,这样的方法会起作用:

I agree with @cris, there are better ways to represent your data. However, something like this would work if you still want to do use a 3D bar plot:

figure
hold on

for i = 1:5
    Ai = A(10*(i-1)+1:10*i,:);
    h = bar3(1:10,Ai,'stacked');

    for ih = 1 :length(h)
        x = get(h(ih), 'Xdata');
        set(h(ih), 'Xdata', x+i-1);
    end

end
view(3)

这篇关于在 Matlab 中的网格上绘制 3D 条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆