如何在MATLAB中的单个图上添加两个图例? [英] How do I add two legends to a single plot in MATLAB?

查看:899
本文介绍了如何在MATLAB中的单个图上添加两个图例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB中的图上添加两个图例.我该怎么办?

I'd like to add two legends to a plot in MATLAB. How can I do this?

推荐答案

您可以创建第二个叠加轴,并带有其自己的图例(当然在其他位置).

You could create a second superimposed axis, with a legend of its own (in a different location of course).

这是一个简单的例子:

%# create some plot with a legend
hAx(1) = axes();
hLine(1) = plot(1:10, 'Parent',hAx(1));
set(hAx(1), 'Box','off')
legend(hLine(1), 'line')

%# copy the axis
hAx(2) = copyobj(hAx(1),gcf);
delete( get(hAx(2),'Children') )            %# delete its children
hLine(2) = plot(sin(1:10), 'Color','r', 'Parent',hAx(2));
set(hAx(2), 'Color','none', 'XTick',[], ...
    'YAxisLocation','right', 'Box','off')   %# make it transparent
legend(hLine(2), {'curve'}, 'Location','NorthWest', 'Color','w')

这篇关于如何在MATLAB中的单个图上添加两个图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆