I had no luck even "handle diving" with <Yair's undocumented tool> to try to get access to the lines and/or legend text properties internals with the current legend syntax. But, if you revert to the old syntax that still has the internal axes it's based on, you can get the handles to the actual legend lines objects and move them at will. Of course, doing this breaks a lot of the newer features like the title, multiple columns and auto-updating content, etc., ...
legend({'first graph $y=x$', sprintf('%s\n%s', 'second graph', '$y=x^2$'), sprintf('%s\n%s', 'third graph', '$y=x^3$')}, 'Interpreter', 'latex','location','northwest')
[~,hIcons]=legend({'first graph $y=x$', sprintf('%s\n%s', 'second graph', '$y=x^2$'), sprintf('%s\n%s', 'third graph', '$y=x^3$')}, 'Interpreter', 'latex','location','northwest')
Warning: Calling legend with multiple outputs will not be supported in a future release.
hIcons =
9x1 graphics array:
Text (first graph $y=x$)
Text (second graph, $y=x^2$)
Text (third graph, $y=x^3$)
Line (first graph $y=x$)
Line (first graph $y=x$)
Line (second graph/$y=x^2$)
Line (second graph/$y=x^2$)
Line (third graph/$y=x^3$)
Line (third graph/$y=x^3$)
hIcons(6).YData=hIcons(6).YData+0.1;
hIcons(8).YData=hIcons(8).YData+0.1;
The warning is troublesome; that doesn't yet show in my R2021b locally, but until Mathworks comes up with solutions for such things, it's a real kick in the teeth.
There may be some trapdoor to get to these line objects if poke at the present legend object sufficiently, but I couldn't find them easily.
ADDENDUM
I didn't think of it at the time and haven't looked to see but should double-check the position of the text objects -- it may be their vertical position is just what you need, not the empirical move made above...
Well, it's not much code, let's look and see...
[~,hIcons]=legend({'first graph $y=x$', sprintf('%s\n%s', 'second graph', '$y=x^2$'), sprintf('%s\n%s', 'third graph', '$y=x^3$')}, 'Interpreter', 'latex','location','northwest')
Warning: Calling legend with multiple outputs will not be supported in a future release.
hIcons =
9x1 graphics array:
Text (first graph $y=x$)
Text (second graph, $y=x^2$)
Text (third graph, $y=x^3$)
Line (first graph $y=x$)
Line (first graph $y=x$)
Line (second graph/$y=x^2$)
Line (second graph/$y=x^2$)
Line (third graph/$y=x^3$)
Line (third graph/$y=x^3$)
hIcons(2).VerticalAlignment='top';
hIcons(3).VerticalAlignment='top';
is too much as the y postions are the same. Looks like adjusting the line position is the better option, unfortunately.
ADDENDUM
I believe the lack of access to adjust the legend lines/text is a significant defect in newer version and should be subject of formal enhancement/bug report.