bar-chartscilab

Change the colors of a bar histogram in Scilab


I have a 40*2 matrix and I want to represent it in a bar format in SCILAB. And i want the data to be stacked.

So I checked and used the bar function, and for now it goes like this :

bar(Data,'stacked');

stacked bar histogram for a 40*2 matrix in green and blue

I want to customize the color of the graph by giving differents pairs of colors for each bar of the plot.

I tried to use a "vector of M strings" like suggested on the scilab help, but it takes into account only the first two colors specified, as I expected.

bar(Data,['yellow','red','cyan,'black'],'stacked']

stacked bar histogram for a 40*2 matrix, in red and yellow

Does anyone here might have a clue as to how I can do that ? Thanks a lot in advance

EDIT : So thanks to S. Gougeon i can do it. But now I want to use the barh() function instead of the bar(). I tried to change only the bar by barh, but obviously it didn't work. I tried then to do it with a single bar :

y=[40 60]; barh(1,y,'stacked');

I get the following image and these warning messages : WARNING: Transposing row vector Y to get compatible dimensions WARNING: Transposing data matrix Y to get compatible dimensions bar chart with one horizontal bar that goes from 40 to 100

I don't know why I have those warnings, since it's correctly working with bar(); and there is no difference in the help for the barh() function. Moreover there is only the second data on the chart, and I still don't know why.


Solution

  • For the barh() issues:

    This one can be worked around by using bar(), and then rotate the axes by 90°:

    gca().rotation_angles(2) = 0;
    

    enter image description here