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 data2
3、在legend中使用带下标 希腊字母
最简单的方法:
legend('\tau_{1}')
得到的效果:
下标的符号如上图所示,希腊字母表间legend的帮助文件。
但是得到的字体明显不好看,特别是那个下标,简直丑爆了。但是,非常好的是MATLAB支持Latex啊,嘿嘿,这真是个好东西。先看下legend帮助文件里面怎么使用Latex的:
By default, MATLAB supports a subset of TeX markup. Use TeX markup to add superscripts and subscripts, modify the font type and color, and include special characters in the text.
the
Interpreter
property set to'tex'
.
就是我们需要改下legend的‘Interpreter
’属性就行了,如下:
legend({'$\tau_{1}$'},'Interpreter','latex');
啥,你的legend里面有多个标注,这样来:
legend({'$\tau_{1}$','$\tau_{2}$'},'Interpreter','latex');
怎么生成Latex代码?我的方法是现在公式编辑器里面打入需要的公式,然后用一个叫“Mathpix sniping tool ”的强大公式识别软件(用到就爱上了,再也离不开了),复制到上面的大括号里面就完事了。上结果:
这个下标是不是美滋滋。