3D grouped bar graph

Hi I have two grouped bar graphes. The first one is for x=1 and the second one is for x=2. I want to combine both at the same with a 3D view. My code is here
clear all
clc
close all
%at x=1
a=[11;7;14;11;43;38];
b=[11;13;17;13;51;46];
c=[9;11;20;9;69;76];
y1=[a b c];
%at x=2
d=[38;61;75;38;28;33];
e=[46;132;135;88;36;51];
f=[76;186;180;115;85;72];
y2=[d e f];
figure(1)
bar3(y1,'grouped')
title('Grouped Style')
ylabel('y1')
zlabel('z1')
figure(2)
bar3(y2,'grouped')
title('Grouped Style')
ylabel('y2')
zlabel('z2')
Any help is appreciated!
Thank you

回答 (2 件)

Sam Penwell
Sam Penwell 2017 年 6 月 12 日

2 投票

I ran into the same problem. I was able to solve it by using the Xdata of the plot as described for a different case here:
I would suggest you try this:
clear all
clc
close all
%at x=1
a=[11;7;14;11;43;38];
b=[11;13;17;13;51;46];
c=[9;11;20;9;69;76];
y1=[a b c];
%at x=2
d=[38;61;75;38;28;33];
e=[46;132;135;88;36;51];
f=[76;186;180;115;85;72];
y2=[d e f];
figure(1);
hold on;
%First x value
xval = 1;
h = bar3(y1,'grouped');
Xdat = get(h,'Xdata');
for ii=1:length(Xdat)
Xdat{ii}=Xdat{ii}+(xval-1)*ones(size(Xdat{ii}));
set(h(ii),'XData',Xdat{ii});
end
%Second x value
xval = 2;
h = bar3(y2,'grouped');
Xdat = get(h,'Xdata');
for ii=1:length(Xdat)
Xdat{ii}=Xdat{ii}+(xval-1)*ones(size(Xdat{ii}));
set(h(ii),'XData',Xdat{ii});
end
xlim([0 3]);
view(3);
title('Grouped Style')
xlabel('x');
ylabel('y');
zlabel('z');

2 件のコメント

Shashibhushan Sharma
Shashibhushan Sharma 2018 年 8 月 21 日
Dear all, I want to plot a 3D bar graph for a given X Y Z row matrix. actually I want to plot bar of Z for a specified X and Y. How to plot it please help me.
Tuhin Choudhury
Tuhin Choudhury 2020 年 11 月 5 日
Thank you for this Sam Penwell, I was facing the same issue and your approach was very helpul.

サインインしてコメントする。

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 24 日

0 投票

I think the only way is to group data into one matrix (bar2 groups data row-wise)
figure(1)
bar3([y1,y2],'grouped')

3 件のコメント

friet
friet 2016 年 10 月 24 日
編集済み: friet 2016 年 10 月 24 日
Thanks for your reply. However, I want to group the second set of data in x direction. With
bar3([y1,y2],'grouped')
I group y1 and y2 at the same x - axis. I want y1grouped at x=1 and y2 at x=2. Like in the figure below but grouped.Please help!
Thanks
Massimo Zanetti
Massimo Zanetti 2016 年 10 月 25 日
As far as I know, it is not possible to have groups with different "x" coordinate. Looking forward to see if someone else can solve it.
ALEX CHICAIZA
ALEX CHICAIZA 2020 年 11 月 10 日
Help I need similar but "stacked". How I can do it?

サインインしてコメントする。

質問済み:

2016 年 10 月 23 日

コメント済み:

2020 年 11 月 10 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by