当您还使用过Fit,Matlab时,从图例中删除对象 [英] Remove Objects from Legend When You Have Also Used Fit, Matlab

查看:568
本文介绍了当您还使用过Fit,Matlab时,从图例中删除对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经绘制了数据点,并在Matlab中使用拟合"来拟合它们之间的指数曲线.问题在于,通过拟合函数,我得到了想要绘制的拟合线,而且在常规标记上还获得了额外的标记.我通过在不需要的标记上绘制所需的标记来解决此问题,从而使它们无法被看到.现在解决问题.当我想显示图例时,这些点也位于其中.由于两个标记都隐藏在拟合函数中,如何在不删除拟合线的情况下从图例中删除标记?我可以停止拟合"来绘制不需要的标记吗?因此,我想在下图中删除名为"hoff"的蓝点.

I've plotted data points and fitted an exponential curve between them using 'fit' in Matlab. The problem is that with the fit-function I got the fitted line I wanted to plot, but also extra markers on top of my regular markers. I solved this problem by plotting the wanted markers on top of the unwanted so that they couldn't be seen. Now to the problem. When I want to show the legends those dots are also in there. How can I remove the markers from the legend without removing the fitted line since both of them are hidden inside the fit-function? Can I stop 'fit' from plotting the unwanted markers? So, I want to remove the blue dot called 'hoff' in the picture below.

推荐答案

您可以通过手动省去不想出现在图例中的行的句柄来省去图例条目.试试这个:

You can leave out legend-entries by manually leaving out the handles of the lines, that you dont want to be in the legend. Try this:

%if you plot something, that you want showing up in the legend, save its handle:
h_line = plot(x,y)
%you dont want to show up this line? dont do anything, just plot it:
plot(myMarker)
%then set the legend-> you can add the text for your legend-entries with 
%a cell-array   containing the strings you want to show up:
legend([h_line another_line],{'Text1' 'Text2'})

通过示例(请参阅注释),我得出了这个解决方案:

with the example (see comments) I came to this solution:

close all
X=[1:10];
Y=X*0.5+0.1;
ft = fittype('poly2'); 
f = fit(X', Y',ft); 
ha=plot(f)
hold on
hc=plot(X,Y)
hb=errorbar(X, Y, X*0.1, 'squarek','MarkerFaceColor','k','markersize',5)
hleg1 = legend([ha hc],{'hnh','ghg'});

->这仅是分割plot命令.希望对您有帮助...

-> this is just about splitting the plot-command. Hope that helps...

结果应如下所示:

这篇关于当您还使用过Fit,Matlab时,从图例中删除对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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