# different color bar graph

7 messages
Open this post in threaded view
|

## different color bar graph

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

## Re: different color bar graph

 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.
Open this post in threaded view
|

## Re: different color bar graph

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

## Re: different color bar graph

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

## Re: different color bar graph

 and this : https://gyazo.com/5c2ba1d72734c42c03033c13b883757fthe distant must to be egual! -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html