MATLAB图中选定图对象的图例 [英] legend for selected plot objects in MATLAB figure

查看:158
本文介绍了MATLAB图中选定图对象的图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于MATLAB图形,我有类似的东西:

For a MATLAB figure, I have something like:

figure; hold on;
line ( [1 2], [3 4] );
line ( [5 6], [7 8] );

plot(x1,y1,'r.');
plot(x2,y2,'b.');

其中x1,y1,x2,y2都是向量.

where x1,y1,x2,y2 are all vectors.

如何仅对最后两个图添加legend,而不对两行添加legend?

How can I add legend for only the last two plots, not for the two lines?

推荐答案

您将必须获取最后两个图的句柄,并告诉legend仅为这两个图绘制.例如:

You will have to get the handles for the last two plots and tell legend to plot only for those two. For example:

h1 = plot(x1,y1,'r.');
h2 = plot(x2,y2,'b.');
legend([h1,h2],'red','blue')

这篇关于MATLAB图中选定图对象的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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