3D bar y axis problem

14 views (last 30 days)
Stefano Di Benedetto
Stefano Di Benedetto on 18 Sep 2018
Edited: jonas on 25 Sep 2018
Hello everybody
I have the following problem: when I use bar3 function I am not able to have a multiplot bar along x-axis.
As you can see by the picture
I just want to put in only one bar3 plot the three subplot.
How can I add my subplots along the x axis?
  2 Comments
jonas
jonas on 19 Sep 2018
Maybe you could get the desired effect by being creative with hist3.

Sign in to comment.

Answers (1)

dpb
dpb on 20 Sep 2018
Edited: dpb on 21 Sep 2018
OK, try this...
% first just make some similar sample data...
z1=repmat([0.07 0.062 0.055 0.05].',1,3);
z1=z1+rand(size(z1))/100;
z2=z1*2/3;
z2=z2+rand(size(z1))/100;
z=[z1(:) z2(:)].';
z=reshape(z(:),[],3);
L=length(z); % length of z (number total bars)
y=[1:L/2]; % grouping by 2
y=[y;y].'; % nominal position each group
y=y+[-1 1]/(L-1); % offset for each group bar from nominal
y=y';y=y(:) % orient as vector
% Preliminaries done, now plot and modify...
hB3=bar3(y,z); % base plot
hAx=gca; % save axis handle
hAx.YLim=[0.5 4.5]; % manipulate axes for visual effect
hAx.XTick=[];
hAx.YTickLabel=[0 33 65 100]; % nominal positions values
% now we get to the color manipulation
L2=L/2; % for number groups
c1=ones(6,4); c3=3*ones(6,4); % color first, last bar ordinal number. Six vertices/bar surface
c=repmat([c1; c3],L2,1) % alternate colors by bar for the four nominal groups
for i=1:length(hB3) % set the CData to the new pattern
hB3(i).CData=c;
end
Results in
In the end, the actual code isn't too bad, but digging through the weeds to understand how to do the manipulation is certainly not simply determined; especially for any user without significant familiarity with HG.
TMW really, really needs to find some ways to make the interface to the internals much simpler to accomplish such things than is. For bar3 and bar specifically, creating handles and exposing them for the individual bars so could just use a .FaceColor property with an index by position would be pretty simple to implement it would seem.
The higher level interface should, obviously, implement the 'grouped' option with more than one series and this particular problem would all disappear automagically.
  4 Comments
jonas
jonas on 25 Sep 2018
The TMW works in mysterious ways :)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!