0
votes

I'm using Matlab R2020b.

Why are bar outline lines (the black ones) very wide using a loop to change the colours for each bar?

col(1,:) = [1 0 0]; % -- red
col(2,:) = [0 1 0]; % -- green
col(3,:) = [0 0 1]; % -- blue
col(4,:) = [1 1 0]; % -- yellow
figure
b(1) = bar(dt3(1),p3(1),'FaceColor',col(1,:),'BarWidth', 1, 'LineWidth',0.001);
hold on;

for i=2:length(dt3)
    if cid3(i) ~= cid3(i-1)
        if c == 4
            c = 1;
        else
            c = c + 1;
        end
        
        b(i) = bar(dt3(i),p3(i),'FaceColor',col(c,:),'BarWidth', 1, 'LineWidth',0.001);
        txt{k} = num2str(cid3(i));
        lh(k) = b(i);
        k  = k + 1;
    else
        b(i) = bar(dt3(i),p3(i),'FaceColor',col(c,:),'BarWidth', 1, 'LineWidth',0.001);
    end
end

enter image description here

As can you see, it turns difficult to see the colorurs right because the black bars are almost wider.

However, if I plot the same bar graph directly without changing colours they are thinner (the blue ones)

bar(dt3,p3);

enter image description here

The dark blue bars are thinner.

1

1 Answers

1
votes

SOLVED.

Just changing the bar lines in the first code (the one which has loop) and removing the edge lines:

b(i) = bar(dt3(i),p3(i),'FaceColor',col(c,:),'BarWidth', 1, 'LineWidth',0.001);

to

b(i) = bar(dt3(i),p3(i),'FaceColor',col(c,:),'BarWidth', 0.8, 'EdgeColor','none');

where BarWidth = 0.8 is the default bar width size.

col(1,:) = [1 0 0]; % -- red
col(2,:) = [0 1 0]; % -- green
col(3,:) = [0 0 1]; % -- blue
col(4,:) = [1 1 0]; % -- yellow
figure
b(1) = bar(dt3(1),p3(1),'FaceColor',col(1,:),'BarWidth', 0.8, 'EdgeColor','none');
hold on;

for i=2:length(dt3)
    if cid3(i) ~= cid3(i-1)
        if c == 4
            c = 1;
        else
            c = c + 1;
        end
        
        b(i) = bar(dt3(i),p3(i),'FaceColor',col(c,:),'BarWidth', 0.8, 'EdgeColor','none');
        txt{k} = num2str(cid3(i));
        lh(k) = b(i);
        k  = k + 1;
    else
        b(i) = bar(dt3(i),p3(i),'FaceColor',col(c,:),'BarWidth', 0.8, 'EdgeColor','none');
    end
end

I have to still change the colours, they look very shiny.

enter image description here