You can usually hack this thing by making a second invisible axis on top of the first, for example:
t=0:.01:(2*pi); y=[sin(t);sin(t-pi/12);sin(t-pi/6);sin(t-pi/4)]; figure subplot(6,1,5) plot(t,y) xlim([0 2*pi]) l1 = legend('1', '2'); pos = l1.Position; set(l1, 'Position', pos - [pos(3) 0 0 0]); legend boxoff ax2 = copyobj(gca, gcf); set(ax2, 'visible', 'off', 'clipping', 'off') kids = ax2.Children; set(kids, 'visible', 'off', 'clipping', 'off') set(ax2, 'children', kids([3:4 1:2])) l2 = legend(ax2, '3', '4'); legend(ax2, 'boxoff') legend boxoff
Note that this is fragile (for example, it does not handle window resizing in my version of MATLAB).
Tokkot
source share