www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/SpecifyLegendLocationExample.m

    %% Specify Legend Location and Orientation
% Plot two lines and add a legend. Control the location of the legend by
% setting the |Location| property. Control the orientation by setting the
% |Orientation| property.

x = -pi:pi/20:pi;
y1 = sin(x);
plot(x,y1)

hold on
y2 = cos(x);
plot(x,y2,'--')
hold off

legend('sin(x)','cos(x)','Location','northwest','Orientation','horizontal')