Matlab图例横排竖排(legend函数)

x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = cos(2*x);
plot(x,y2)

y3 = cos(3*x);
plot(x,y3)

y4 = cos(4*x);
plot(x,y4)
hold off

legend({
    
    'cos(x)','cos(2x)','cos(3x)','cos(4x)'},'Location','northwest','NumColumns',2)
set(gca,'FontName','Times New Roman','FontSize',14);

在这里插入图片描述

x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = cos(2*x);
plot(x,y2)

y3 = cos(3*x);
plot(x,y3)

y4 = cos(4*x);
plot(x,y4)
hold off

legend({
    
    'cos(x)','cos(2x)','cos(3x)','cos(4x)'},'Location','northwest','NumColumns',4)
set(gca,'FontName','Times New Roman','FontSize',14);

在这里插入图片描述

x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = cos(2*x);
plot(x,y2)

y3 = cos(3*x);
plot(x,y3)

y4 = cos(4*x);
plot(x,y4)
hold off

legend({
    
    'cos(x)','cos(2x)','cos(3x)','cos(4x)'},'Location','northwest','NumColumns',1)
set(gca,'FontName','Times New Roman','FontSize',14);

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/iii66yy/article/details/134986569