Code covered by the BSD License  

Highlights from
hackLegend

image thumbnail
from hackLegend by Doug Hull
Changes legend to repeat marker

hackLegend(h)
function hackLegend(h)
% HACKLEGEND will change legend to show repeated markers
%
% x = linspace(0,2*pi,100);
% y = sin(x);
% plot(x,y,'r-',x,y+1,'ko',x,y+2,'g.')
% h = legend({'alpha', 'bravo', 'charlie'})
% hackLegend(h);

n = 3; %num reps of symbol

lineKids = findobj(h,               ...
          '-not','Marker'   ,'none' ...
                ,'lineStyle','none');


for i = 1 : numel(lineKids)
    xxx = get(lineKids(i),'xData');
    yyy = get(lineKids(i),'yData');
          set(lineKids(i),'xData', xxx + [-0.1 0 +0.1] ...
                         ,'yData', repmat(yyy,1,n));
end

% Copyright 2007 - 2009 The MathWorks, Inc.

Contact us