help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: different color bar graph


From: Przemek Klosowski
Subject: Re: different color bar graph
Date: Thu, 13 Jun 2019 10:28:10 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

On 6/11/19 11:40 PM, shivax via Help-octave wrote:
T=[4 5 -1 4 -9 -4]

i want to color green the positive number and color green the other

hold on
figure;
pos=find(T>0);
neg=find(T<=0);

h=bar(pos,T(pos),'facecolor','g');
v=bar(neg,T(neg),'facecolor','r');

'help bar' shows an example of what you're trying to do; please always read the help first.

You have to split your data into columns which you then can define properties for. Fortuitously, your data splits evenly between negative and positive, so

tt=[T(pos);T(neg)]'
h=bar(tt);

will use different colors. If you want specific colors, you'd get the figure handle and modify the properties like so:

set(h(1),"facecolor",'g')
set(h(2),"facecolor",'r')

I leave it as an exercise to figure out what to do if the number of positive values was different than negatives.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]