As far as I know the syntax [lgd,icons,plots,txt] = legend(..) is not reccomended. Notice in fact that by simply calling icons as output you destroy the legend layout:
plot(rand(10,3));
[lh,icons,~,~] = legend('1st','2nd','3rd');
lh.Units = 'centimeters';
lh.Orientation = 'horizontal';
lh.Location = 'southOutside';
Therefore, after calling icons you need to replace ALL the objects in the legend. To do so, consider that icons objects of type 'Line' are twice the number of lines (in this case 6)
ls= findall(icons,'Type','Line')
ls =
6×1 Line array:
Line (1st)
Line (1st)
Line (2nd)
Line (2nd)
Line (3rd)
Line (3rd)
For every line that you see in the legend, you have 2 line objects! In parentheses the corresponding item label is reported by Matlab. For each line, the first object associated to it is the line object which is plotted in the legend, while the second one is its central position (inspect both XData and YData of all ls(k) for k=1,...,6). Thus, to make your custom legend, change all the ls lines XData and YData accordingly (for example, YData must be all the same while XData must be properly spaced). Remember, you also have to adjust text objects position.
My suggestion is to set 'Units' to 'normalized'.
Let me know if you need help.
0 Comments
Sign in to comment.