MATLAB Answers

Rengin
0

Bar charts with different colors

Asked by Rengin
on 19 Nov 2019 at 14:06
Latest activity Edited by KALYAN ACHARJYA on 19 Nov 2019 at 14:45
% Dear users, when I run the code I want to get bars in different colors (not one color). Could you please tell me how to do it?
% Thanks in advance!
SC01_LS02_TVSR_112=[0.0127 0.0139 0.0058 0.0112 0.0048 0.0126 0.0037];
bar(SC01_LS02_TVSR_112);

  0 Comments

Sign in to comment.

2 Answers

Answer by Rik
on 19 Nov 2019 at 14:38

Depending on your release you can set the CData property of every bar, or you will need to create separate bar objects and set the FaceColor property.

  0 Comments

Sign in to comment.


Answer by KALYAN ACHARJYA on 19 Nov 2019 at 14:44
Edited by KALYAN ACHARJYA on 19 Nov 2019 at 14:45

One way:
SC01_LS02_TVSR_112=[0.0127 0.0139 0.0058 0.0112 0.0048 0.0126 0.0037];
col=['r','y','b','k','b','k','y']; % Decide color as you want
for i=1:length(SC01_LS02_TVSR_112)
h=bar(i,SC01_LS02_TVSR_112(i));
set(h,'FaceColor',col(i));
hold on;
end

  0 Comments

Sign in to comment.