Legend with multiple colors for a single bar plot
Show older comments
I have a single bar plot and i have managed to color the bars in 3 different colors. When I try to create a legend, it does only show one color. How can i add the two other colors to the legend when i only have one bar plot?
My code looks like this:
figure(2)
bar_h = bar(T_orderO);
title('Tid brugt på hvert spørgsmål')
xlabel('Spørgsmålsnummer')
ylabel('Tid (s)')
set(gca,'XLim',[0 numel(O)+1])
set(gca,'xticklabel',O)
set(gca,'XTick',1:1:numel(O))
set(gca,'YLim',[0 max(T_orderO)*1.1])
%set(gca,'YTick',0:max(T_orderO)+1)
hbar_child = get(bar_h, 'Children');
set(hbar_child,'CData',T_orderO);
set(hbar_child,'CDataMapping','direct');
index = 1:numel((R_orderO));
for i = 1:length(R_orderO)
if R_orderO(i) == -1
index(i) = 1;
elseif R_orderO(i) == 1
index(i) = 2;
else
index(i) = 3;
end
end
mycolor=[1 0 0; 0 1 0; 1 1 1];
colormap(mycolor);
set(hbar_child, 'CData',index);
Accepted Answer
More Answers (0)
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!