Warning when using 'Box','off' in legend and the box of the legends keeps showing!
2 次查看(过去 30 天)
显示 更早的评论
Does any one know why the following error is generated and the box of the legend is still showing?
x=0:0.1:2*pi;
y1=sin(x);
y2=cos(x);
plot(x,y1);
hold on
plot(x,y2);
axis tight
legend('sin','cos','Location','North','Box','off')
Warning: Ignoring extra legend entries.
> In /Applications/MATLAB_R2014b.app/toolbox/matlab/scribe/private/legendHGUsingMATLABClasses.p>set_children_and_strings at 649
In /Applications/MATLAB_R2014b.app/toolbox/matlab/scribe/private/legendHGUsingMATLABClasses.p>make_legend at 312
In /Applications/MATLAB_R2014b.app/toolbox/matlab/scribe/private/legendHGUsingMATLABClasses.p>legendHGUsingMATLABClasses at 241
In legend at 118
0 个评论
采纳的回答
Geoff Hayes
2015-1-14
Mohammad - the line of code
legend('sin','cos','Location','North','Box','off')
seems to be considering the final two inputs/strings as labels for curves that don't exist. If you just execute the command
h = legend('sin','cos','Location','North')
it works without warning, and moves the legend to the appropriate location.
Glancing at the documentation for legend, there doesn't seem to be an option that allows you to set the curve labels and the box in this manner. There are "signatures" for Location and for Orientation, but when it comes to using the other parameters, the one signature seems to be just
legend(strings,Name,Value)
So if you were to try
legend({'sin','cos'},'Box','off')
then no warning would be generated, but on my version of MATLAB (R2013a), only part of the box is removed. In order to remove all of the box, I either have to do
h = legend('sin','cos','Location','north');
set(h,'boxoff');
or
h = legend('sin','cos','Location','north');
set(h,'box','off');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!