3.5 | 3 ratings Rate this file 25 Downloads (last 30 days) File Size: 1.86 KB File ID: #28513
image thumbnail




19 Aug 2010 (Updated )

Function similar to the matlab stem3 but drawing bars instead of lines with markers.

| Watch this File

File Information

h = StemBar(x,y,z,color,width)
Function is similar to stem3, but instead of lines with markers plotting
3d bars

StemBar(x,y,z) - draws bars with a height z at the values specified in x
and y. x, y, z - should be a vectors.
StemBar(z) - draws bars with a height z at the xy-plane
StemBar(...,color) - If color is a single character string chosen from the
list 'r','g','b', 'c','m','y','w','k', or an RGB row vector triple,
[r g b], the bars are filled with the constant specified color. If color
is a vector of length numel(x)*6 each faces will be filled with specified
color in the corresponding row.
StemBar(...,width) - specified a width of bars
h = StemBar(...) - return a handle


h = StemBar(1:10);

Author: Grzegorz Knor
e-mail: gknor@ippt.gov.pl

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
22 Dec 2010 Jiaqi

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
for i=1:length(h)/6
ztop = get(h(i*6),'Zdata');
ztop = ztop';
for j=1:6
% now give the color specification
% and run 'stembar' again
zdata = zdata';

colormap cool
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 Jiaqi

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);
for i=1:length(h)/6
ztop = get(h(i*6),'Zdata');
ztop = ztop';
for j=1:6

colormap cool
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.

22 Dec 2010 Jiaqi

This is what I am looking for and it works fine. Thanks a lot.

09 Oct 2010 Grzegorz Knor

Thanks for your comment Olbert.
It was an error in example. Should be:

I uploaded a new version without this error.

If you do not want chart where each side of every bar has a different colour, you can run it in this way:
color = repmat(rand(1,25),6,1);

If you have a better idea please upload it :)


09 Oct 2010 Olbert

Edit: Im not saying that it does work in Matlab 2010a, I just know that it doesnt work in Matlab 2009b. I very much doubt that it does, though I do not have 2010a so, it may work with updated functionality of some of the functions it uses. As I said, if this is a Matlab version issue then it is still an example of poor coding, more likely its just an example of poor coding and doesnt work on any version.

09 Oct 2010 Olbert

This is a good idea but it is implemented poorly. A lot more work needed to be done before it was posted here. For starters make sure the example code works! It does not. That is extremely poor coding.

It's basic functionality works but the adding colours feature is poorly implemented. I have no idea why anyone would want to produce a 3D bar chart where each side of every bar has a different colour - that's really pointless. There should be easy functionality to add a vector of colours with one colour for one bar.

If these problems are related to it only working in the 2010a Matlab version then if nothing else it is still an example of extremely poor coding style.

09 Oct 2010

It was an error in example.

Contact us