79575866

Date: 2025-04-15 19:09:16
Score: 1
Natty:
Report link

enter image description here

f1 = figure;

x = linspace(0, 2*pi);

hold on;
plot(x, sin(x));
plot(x, sin(x * .5), '--');
plot(x, cos(x));
plot(x, cos(x * .5),':');
hold off

legend([f1.CurrentAxes.Children(1), f1.CurrentAxes.Children(2)], 'p1', 'p2', Location='NorthEastOutside');
legend(copyobj(f1.CurrentAxes, f1), [f1.CurrentAxes.Children(3), f1.CurrentAxes.Children(4)], 'p3', 'p4', Location='SouthEastOutside');
f1.CurrentAxes.Visible = 'off';

This approach does not create extra variables but uses the Graphics Object Hierarchy of the figure.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: tormec