Different colors for each bar
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have this problem. I have this data:
x=file.variable %file text (ABR CAM CAL BAS EML...etc)
y=file.variable %number (12 52 32 36 59....etc
z=file.variable %number (2.3 5.4 8.3 1.3....etc)
I would like a bar plot with different colors for each bar (on base of z value) using for example colorbar. Now I have this code, maybe there is some errors within function:
x = file.variable_text;
y = file.variable_number;
z = file.variable_percentage;
[~,arr] = sort(z,'ascend'); %order data
X = reordercats(categorical(x),x(arr));
How I can do?
0 Kommentare
Antworten (1)
Cris LaPierre
am 24 Mär. 2022
b = bar(rand(10,1));
b.FaceColor = 'flat';
b.CData(2,:) = [.5 0 .5];
2 Kommentare
Cris LaPierre
am 24 Mär. 2022
My reading of the documentation would indicate this is the recommended approach for setting bar color. There does not appear to be an option to automatically set the color based on value.
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!