3D bar y axis problem

19 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
dpb
dpb on 19 Sep 2018
Edited: dpb on 19 Sep 2018
You can't do that with default options in bar3; it's pretty feeble.
I don't know if there's anything at FEX or not.
I don't have time to play at the moment; best I can think of is you might be able to manufacture it if you load the 3-columns with your data and IF bar3 returns a bar handle for more than the 3 columns that you can manually color.
Other than that, you'd have to fake it by calling bar3 twice with two sets of data; one with NaN place holders for the yellow bars and another with placeholders for the blue.
It works to do "fake grouped" bar plots on two y axes, for example, but I've never tried it with bar3.
Bestest ideas I've got at the moment...none too good, sorry...
ADDENDUM
I didn't have much time but the "fake data" NaN doesn't work automagically with bar3 as does with bar -- being 3D, the object is a surface and doesn't act the same with ignoring NaN entirely such as other plotting routines.
There is, however, the CData vertex color data and probably one can manage to set color properties such as to get the desired effect with sufficient "handle-diving" into the internal storage order and color properties.
jonas
jonas on 19 Sep 2018
Edited: 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
dpb
dpb on 25 Sep 2018
Interesting. Why doesn't TMW fix/enhance the user interface instead of needing clever workarounds, though? :)
jonas
jonas on 25 Sep 2018
Edited: jonas on 25 Sep 2018
The TMW works in mysterious ways :)

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!