change color for specifics bars
Afficher commentaires plus anciens
I have this code to create bar plot. but I would like to change color for specifics bars.
On the base of index, I would like that data with index (in xlabel) < 16 have to be red, >16 green, <5 blu and index ==16 green and ==8 blu
How can I do?
%Order table
z = sortrows(table,'variable','ascend');
%X
x = z.variable;
idxx=(1:20)'
x=z.variable(idxx)
%Y
y= z.variable1;
idxy=(1:20)'
y=z.variable1(idxy)
M2=[x y]
h=bar(idxx,M2(:,2))
h.FaceColor='flat';
xticks(1:numel(x))
xticklabels(x)
hAx=gca;
hAx.XTickLabelRotation=0;
%target
labels = categorical(z.textvariable);
xt = get(gca, 'XTick');
set(gca,'xticklabel',x)
text(xt, y, labels, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
%title
title('title')
xlabel('labelx','FontSize',14)
ylabel('labely','FontSize',14)
%legend
legend({'name',},'Location','northeast','Orientation','vertical')
lgd = legend;
lgd.FontSize = 14;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Object Properties 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!
