different color bar graph

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

different color bar graph

help-octave-3
hi, look this array

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');


i see only chart green color :(

https://gyazo.com/2fb338f68c85076765870c8521c84337






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: different color bar graph

Przemek Klosowski-7
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 | Threaded
Open this post in threaded view
|

Re: different color bar graph

help-octave-3
thank you...you solved my problem..

and how can I plot 3 different bar chart in one? (the same figure)

https://gyazo.com/6cfa20fe1b67984aa0b0fd85d6ec82ba 






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: different color bar graph

help-octave-3
In reply to this post by Przemek Klosowski-7
i try another exampe but i've some problem with you code

Example:

T=[3 4 -1 9 4 1]

if i use your method i see

neg=find(T<=0);
pos=find(T>0);
 tt=[T(pos);T(neg)]'
error: vertical dimensions mismatch (1x4 vs 1x7)

The correct is to see graph below
https://gyazo.com/25616bdbc3a152df1084e3c39e57484c



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: different color bar graph

help-octave-3
Reply | Threaded
Open this post in threaded view
|

Re: different color bar graph

Doug Stewart-4


On Tue, Jun 18, 2019 at 1:00 AM shivax via Help-octave <[hidden email]> wrote:
and this :

https://gyazo.com/5c2ba1d72734c42c03033c13b883757f


the distant must to be egual!



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



try this

clear
T=[3 4 -1 9 4 1]
neg=find(T<=0)
pos=find(T>0)

tt(1,pos)=T(pos)
tt(2,neg)=T(neg)
bar(tt(1,:),'r')
hold( 'on')
bar(tt(2,:))



--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: different color bar graph

help-octave-3