How to select different colors and legend for the bar plot??
Afficher commentaires plus anciens
Hello everyone, I plot this bar plot in order to show the difference between each model (3 models) in condition A and condition B. x = rand(3,2);
x = rand(3,2);
h = bar (x);

I want to set, for example, red for the first model in condition A and blue for condition B (In this model).
As well as two different colors like green and yellow for the second model in each condition. Like this plot below:

And also, set the corresponding legend for each color. So I want to have 6 items in legend (different colors).
Any suggestion is really helpful
Thank you.
Réponse acceptée
Plus de réponses (1)
Sugar Daddy
le 27 Juil 2020
Modifié(e) : Sugar Daddy
le 27 Juil 2020
2nd Part of Question (Pattern Face)
This code is computation intesive and is just for display purpose. (considering that max value is less than 1)
figure,
x = rand(3,2);
c = [1 2 3];
h = bar (c,x,'BarWidth',1);
h(2).FaceColor = 'none';
h(2).LineWidth = 2;
%
jj = 1;
hold on
%
a =gca; clr_array = a.ColorOrder;
for mm = 1:3
for i = x(mm,2):-.01:0
if(jj == 1)
jj = 2;
bar(mm,[0;i],'FaceColor','w','EdgeColor','none','BarWidth',1)
else
bar(mm,[0;i],'FaceColor',clr_array(mm,:),'EdgeColor','none','BarWidth',1)
jj = 1;
end
end
bar(mm,[x(mm,1);0],'FaceColor',clr_array(mm,:),'LineWidth',2,'BarWidth',1)
bar(mm,[0;x(mm,2)],'FaceColor','none','LineWidth',2,'BarWidth',1)
end

Regards,
Sugar Daddy
1 commentaire
BN
le 29 Juil 2020
Catégories
En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
