Code covered by the BSD License  

Highlights from
legend1.m

legend1.m

by

 

17 Dec 2012 (Updated )

Control line and text entries in a legend object, individually.

legend1(s,c,fsz)
function h = legend1(s,c,fsz)
%legend1: easy-to-use variant of legend
% h = legend1(s,c,fsz)
% s:   string cell array of legend entries (n. of entries x 1)
% c:   color array of legend entries in RGB (n. of entries x 3)
% fsz: font size

c = flipud(c);
hLg = legend(s);
hK = get(hLg,'Children');
hT = hK(strcmp(get(hK,'Type'),'text'));
hL = hK(strcmp(get(hK,'Type'),'line'));
for i=1:size(c,1)
    for j=1:3
        cc{i,1}(j) = c(i,j);
    end
    set(hT(i),'Color',cc{i},'FontSize',fsz)
    set(hL(i*2),'Color',cc{i})
end
h = hLg;

Contact us