Color change in grouped line font in Matlab

This is my matrix.

n = 46.4000 51.8000 44.8000 44.9000 67.2000 85.0000 54.4000 60.3000 43.2000 57.0000 51.2000 68.0000 75.2000 76.0000 44.8000 51.3000 67.2000 72.2000 70.4000 71.2000 

If I draw it as bar (n, 'grouped'), it shows

Barplot

I want to change the default colors instead of blue red. I want green and yellow

I tried like this: bar (n, 'grouped', 'g', 'y') But it shows secondplot

Can someone help me?

+6
source share
2 answers

You can use the 'FaceColor' property for object descriptors:

 n=[46.4000 51.8000 44.8000 44.9000 67.2000 85.0000 54.4000 60.3000 43.2000 57.0000 51.2000 68.0000 75.2000 76.0000 44.8000 51.3000 67.2000 72.2000 70.4000 71.2000]; bar_handle = bar(n,'grouped'); set(bar_handle(1),'FaceColor',[0,1,0]) set(bar_handle(2),'FaceColor',[1,1,0]) 

The documentation explains how to set colors here .

+10
source

For matlab2014b and above

Using set no longer works with matlab2014b and gives a message ( Error using subsindex: Function 'subsindex' is not defined for values of class 'matlab.graphics.chart.primitive.Bar'. ).

Try it directly with the pen:

 n=[46.4000 51.8000 44.8000 44.9000 67.2000 85.0000 54.4000 60.3000 43.2000 57.0000 51.2000 68.0000 75.2000 76.0000 44.8000 51.3000 67.2000 72.2000 70.4000 71.2000]; bar_handle = bar(n,'grouped'); bar_handle(1).FaceColor = 'r' bar_handle(2).FaceColor = 'b' 
+1
source

Source: https://habr.com/ru/post/970891/


All Articles