setColor_barByGroup

Change the color of a bar to same groups have the same color.

You are now following this Submission

SETCOLOR_BARBYGROUP change the color of a bar to same groups have the
same color.

SETCOLOR_BARBYGROUP(COLOR) change the color of a bar with N groups
where the i-th group has the COLOR(i, :) color.
COLOR is a N-by-3 matrix color in RGB.

COLOR can be a N-by-1 cell with string matlab colors: 'r','b','g',c', etc.
In this case function rgb.m is needed:
http://www.mathworks.com/matlabcentral/fileexchange/1805-rgb-m

P = SETCOLOR_BARBYGROUP(...) return in the N-by-1 vector P the new patches
associated to each group.

SETCOLOR_BARBYGROUP(AX, ...) AX is the axes to apply the color change.

EXAMPLE: Change the current bar to red [1 0 0], blue [0 0 1] and green [0 1 0]

bar(rand(3,5));
color = [1 0 0; 0 0 1; 0 1 0];
setColor_barByGroup(color);

EXAMPLE: Change the subplot bar to the color {'r', 'b', 'g'} (needed
funciton: rgb.m)

data = rand(3,5);
subplot(1,2,1);
bar(data);
subplot(1,2,2);
bar(data);
p = setColor_barByGroup({'r', 'b', 'g'});

Cite As

Mar Callau-Zori (2026). setColor_barByGroup (https://www.mathworks.com/matlabcentral/fileexchange/34328-setcolor_barbygroup), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Images in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0