Legend with multiple colors for a single bar plot
Mostra commenti meno recenti
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);
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Legend in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!