Set legend color in stacked bar plot
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matlab2010
am 15 Nov. 2013
Kommentiert: Tong Zhao
am 20 Mai 2018
I wish to use a stacked bar graph and specify my own colors. Have do I make the colors in the legend match the bar? thanks
data2D = rand(10,6);
H=bar(data2D, 'stack');
P=findobj(gca,'type','patch');
myC= [0 0 1
1 0 0
1 0.4 0
0 0.8 1
0.6 0 1
0 1 0 ];
for n= 1 : length(P)
set(P(n),'facecolor',myC(n,:));
end
AX=legend(H, {'a','b','c','d','e','f'}, 'Location','Best');
LEG = findobj(AX,'type','text');
set(LEG,'FontSize',8);
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 15 Nov. 2013
close
myC= [0 0 1
1 0 0
1 0.4 0
0 0.8 1
0.6 0 1
0 1 0 ];
data2D = rand(10,6);
H=bar(data2D, 'stack');
for k=1:6
set(H(k),'facecolor',myC(k,:))
end
AX=legend(H, {'a','b','c','d','e','f'}, 'Location','Best','FontSize',8);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!