change color for specifics bars
Show older comments
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;
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!