简体   繁体   中英

Plotting 3D bars over a grid in 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?

Thank you in advance!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM