【问题标题】:legend for selected plot objects in MATLAB figureMATLAB图中选定绘图对象的图例
【发布时间】:2012-11-06 01:31:31
【问题描述】:

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

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 都是向量。

我怎样才能只为最后两个图添加legend,而不是两条线?

【问题讨论】:

标签: matlab legend matlab-figure


【解决方案1】:

您必须获取最后两个绘图的句柄并告诉legend 只为这两个绘图。例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多