Barcharts colours based on other vectors
93 views (last 30 days)
Nikolas Spiliopoulos on 24 Jun 2020
I have 3 vectors a,b,c with 4 numbers in each of them
I create another vector d with all the values of vectors a,b,c Sorted.
then I want to plot a barchart of vector d, BUT I would like to have different colours in the bars based on which vector they belong.
Can you help me with this?
values belong to vector a=green colour
values belong to vector b=blue colour
values belong to vector c=orang colour
Hope the quesiton is clear
thanks in advance
Adam Danz on 24 Jun 2020
The basic idea is to store the output handle to the bar objects
bh = bar(____);
Set the FaceColor to flat
bh.FaceColor = 'flat';
Redefine the CDdata which defines the color of each bar
colorData = bh.CData; % Current color arrangement.
% Example: change color of bar #2 to red
bh.CData(2,:) = [1 0 0];
% Example: define the colors based on the jet colormap
bh.CData = jet(size(bh.CData,1));