matble中legend()函数示例
对于legend函数,我觉得示例更形象,关于解释网上给出的都很完善,或者matble中help legend哦
legend() 将图例添加到图形
x = -pi:pi/20:pi; y1 = sin(x); y2 = cos(x); plot(x,y1,'-ro',x,y2,'-.b') legend('sin(x)','cos(x)') |
图例1 |
x = -pi:pi/20:pi; y1 = sin(x); y2 = cos(x); plot(x,y1,'-ro',x,y2,'-.b') legend('sin(x)','cos(x)','Location','northwest') |
|
x = -pi:pi/20:pi; y1 = sin(x); y2 = cos(x); plot(x,y1,'-ro',x,y2,'-.b') legend('sin(x)','cos(x)','Location','northoutside',... 'Orientation','horizontal') |
|
x = -pi:pi/20:pi; y1 = sin(x); y2 = cos(x); plot(x,y1,x,y2) l = legend('sin(x)','cos(x)'); title(l,'My Legend Title') |
|
x = -pi:pi/20:pi; y1 = sin(x); y2 = cos(x); plot(x,y1,x,y2) l = legend('sin(x)','cos(x)'); title('My Legend Title') |
|
x = linspace(0,4*pi,100); ydata = cos(x) + 0.5*randn(1,100); ycos = cos(x); plot(x,ydata,'*',x,ycos) legend({'Collected Data','y = cos(x)'},... 'FontSize',8,'FontWeight','bold') |
|
>> x = linspace(0,3*pi); y1 = sin(x); p1 = plot(x,y1); y2 = sin(x - pi/4); hold on p2 = plot(x,y2); y3 = sin(x - pi/2); p3 = plot(x,y3); y4 = sin(x - 3*pi/4); p4 = plot(x,y4); y5 = sin(x - pi); p5 = plot(x,y5); hold off legend([p1,p5],'sin(x)','sin(x-\pi)') |