Set legend color in stacked bar plot
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2013-11-15
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!