StemBar
Function similar to the matlab stem3 but drawing bars instead of lines with markers.
Author: Grzegorz Knor
now it works. I need to run stembar again with color information.
%%%%%%%%%%
x=[1 3 2 1 3]';
y=[1 1 2 3 3]';
z=[8.6 6 11.1 14.1 12.4]';
h = stembar(x,y,z); % 5 bars, 30 faces
zdata = ones(length(h),4); % each face has 4 vertices
% specify the color map
k=0;
for i=1:length(h)/6
ztop = get(h(i*6),'Zdata');
ztop = ztop';
for j=1:6
zdata(6*(i-1)+j,:)=ztop;
end
end
% now give the color specification
% and run 'stembar' again
zdata = zdata';
h=stembar(x,y,z,zdata);
colormap cool
colorbar
%%%%%%%%%%%%
It is strange that it doesn't work when I use set(h,'Cdata',zdata),
maybe it's a bug in the command 'fill3'.
however set(h,'facealpha',0.5) works
and set(h,'edgecolor','b') also works.
22 Dec 2010
StemBar
Function similar to the matlab stem3 but drawing bars instead of lines with markers.
Author: Grzegorz Knor
I have a question: how to colormap the bars according to their heights.
I read the help of "bar3", and 'h' in 'stembar.m' returns the handle of each face. So I write the following code:
%%
zdata = ones(length(h),4);
k=0;
for i=1:length(h)/6
ztop = get(h(i*6),'Zdata');
ztop = ztop';
for j=1:6
zdata(6*(i-1)+j,:)=ztop;
k=k+1;
set(h(k),'Cdata',zdata(k,:))
end
end
colormap cool
colorbar
%%
in order to colormap the bars. But it doesn't work.
Could you help me with this problem? I think I haven't totally understand how 'Cdata' works.