Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: help with graph

Subject: help with graph

From: Buffy Summers

Date: 01 Aug, 2007 17:58:38

Message: 1 of 4

I need to make a bar graph. I have 3 values. each value needs a bar in a different color with a differnt name. in the bar command, if I do X=[1 2 3] and than bar(X) I get 3 bars in the same color and i can't change to 3 different color. I also would like to add the group name under each value. Can someone help?

Subject: Re: help with graph

From: us

Date: 01 Aug, 2007 20:13:52

Message: 2 of 4

Buffy Summers:
<SNIP colorful popsicles

> each value needs a bar in a different color with a differnt name...

one of the solutions

% the data
     nb=4;
     yb=rand(nb,1);
     cm=jet(nb); % <- a colormap, use your own nxrgb...
% the engine
     ix=[3,2,4,1]; % <- index into <cm>
     bh=bar(yb);
     ch=get(bh,'children');
     set(ch,...
           'facevertexcdata',ix.');
     colormap(cm);
     colorbar; % <- compare with bar color indices!

us

Subject: Re: help with graph

From: Buffy Summers

Date: 01 Aug, 2007 21:21:00

Message: 3 of 4


Thank you very very much!
Do you also have a solution for the name problem?
for ix to be string and not a number?
Thank you!

"us " <us@neurol.unizh.ch> wrote in message <f8qpi0$62b$1@fred.mathworks.com>...
> Buffy Summers:
> <SNIP colorful popsicles
>
> > each value needs a bar in a different color with a differnt name...
>
> one of the solutions
>
> % the data
> nb=4;
> yb=rand(nb,1);
> cm=jet(nb); % <- a colormap, use your own nxrgb...
> % the engine
> ix=[3,2,4,1]; % <- index into <cm>
> bh=bar(yb);
> ch=get(bh,'children');
> set(ch,...
> 'facevertexcdata',ix.');
> colormap(cm);
> colorbar; % <- compare with bar color indices!
>
> us

Subject: Re: help with graph

From: Buffy Summers

Date: 01 Aug, 2007 22:24:57

Message: 4 of 4

I managed todo it myself. If anyone is interested:

h1=gca;
set(h1,'XTickLabel',['Ct';'C1';'C2';'C3']);

Thank you for the help.

"Buffy Summers" <offdar@gmail.com> wrote in message <f8qtfs$hrn$1@fred.mathworks.com>...
>
> Thank you very very much!
> Do you also have a solution for the name problem?
> for ix to be string and not a number?
> Thank you!
>
> "us " <us@neurol.unizh.ch> wrote in message <f8qpi0$62b$1@fred.mathworks.com>...
> > Buffy Summers:
> > <SNIP colorful popsicles
> >
> > > each value needs a bar in a different color with a differnt name...
> >
> > one of the solutions
> >
> > % the data
> > nb=4;
> > yb=rand(nb,1);
> > cm=jet(nb); % <- a colormap, use your own nxrgb...
> > % the engine
> > ix=[3,2,4,1]; % <- index into <cm>
> > bh=bar(yb);
> > ch=get(bh,'children');
> > set(ch,...
> > 'facevertexcdata',ix.');
> > colormap(cm);
> > colorbar; % <- compare with bar color indices!
> >
> > us
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
patch us 01 Aug, 2007 16:15:20
colormap us 01 Aug, 2007 16:15:20
colorbar us 01 Aug, 2007 16:15:20
code us 01 Aug, 2007 16:15:20
bar us 01 Aug, 2007 16:15:20
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics