matlab 如何创建多行图例

不多废话,代码如下:

x = 0:0.1:2*pi;
y1 = sin(x);
y2 = cos(x);
y3 = tan(x);
y4 = exp(x);

% 获取每个曲线的句柄
h1 = plot(x, y1, 'r', 'LineWidth', 2);
hold on;
h2 = plot(x, y2, 'b', 'LineWidth', 2);
h3 = plot(x, y3, 'g', 'LineWidth', 2);
h4 = plot(x, y4, 'm', 'LineWidth', 2);

% 创建第一行图例并设置标签
lgd1 = legend([h1, h2], 'sin(x)', 'cos(x)', 'Location', 'north', 'Orientation', 'horizontal');
% 图例的方框比较难看,如果觉得可以接受的话也可以把这行代码注释掉
legend boxoff;

% 创建不可见的辅助轴对象,并将第二行图例的位置向下移动
ah = axes('position', get(gca, 'position')+ [0, -0.1, 0, 0], 'visible', 'off');

% 在辅助轴上创建第二行图例并设置标签
lgd2 = legend(ah, [h3, h4], 'tan(x)', 'exp(x)', 'Location', 'north', 'Orientation', 'horizontal');
legend boxoff;

效果如图所示:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值