1、横排
hl = legend('string1', 'string2');
set(hl,'Orientation','horizon')
2、只显示部分曲线的legend
h1 = plot(data1);
plot(data2);
h2 = plot(data3);
legend([h1,h2],'string1','string2'); % only show the legend of data1 and data3
另外一种方式是直接在plot中指定legend中的内容:
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1,'DisplayName','cos(x)')
hold on
y2 = cos(2*x);
plot(x,y2,'DisplayName','cos(2x)')
hold off
legend
得到:
3、在legend中使用带下标 希腊字母
最简单的方法:
legend('\tau_{1}')
得到的效果: