关于MATLAB中legend命令的一些操作

本文介绍了如何在MATLAB中使用legend命令实现横排显示、选择性显示曲线以及在legend中添加带下标和希腊字母。通过设置'Interpreter'属性为'latex',可以利用LaTeX语法美化legend,使得下标效果更佳。使用Mathpix snipping tool工具能方便地将公式转换为LaTeX代码,提升图表的专业性。
摘要由CSDN通过智能技术生成

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}')

得到的效果: 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值