Warning when using 'Box','off' in legend and the box of the legends keeps showing!

2 views (last 30 days)
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

Accepted Answer

Geoff Hayes
Geoff Hayes on 14 Jan 2015
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');
  1 Comment
Mohammad Abouali
Mohammad Abouali on 14 Jan 2015
Edited: Mohammad Abouali on 14 Jan 2015
You are right It does not get multiple properties in one call.
I check and this also works:
legend('sin','cos','Location','North')
legend('boxoff')
Thanks for your help.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!