Legend on graph not displaying correct labels
8 views (last 30 days)
Show older comments
I am trying to plot a graph made of multiple figures. I have labelled each of the legend entries and this code has worked for other multi-figure plots ive done. The legen is printing out as:
1% error
1% error
0.8% error
0.4% error
0.25% error
0.1% error
So it is renaming the 0.8% error as 1% and then the effect is carried on so there isnt even a label for the 0% error now. Bit confused as this code has worked previously with no issues. Does anyone know a fix?
myfigure(1) = openfig('1percreal.fig');
ylim([-120 20]);
title(['Beampatttern , 90' char(176) ' Steer Angle']);
legend({'1% Error'});
myfigure(2) = openfig('08perc.fig');
legend({'0.8% Error'});
myfigure(3) = openfig('buildtol.fig');
legend({' 0.4% Error'});
myfigure(4) = openfig('025perc.fig');
legend({'0.25% Error'});
myfigure(5) = openfig('01perchist.fig');
legend({'0.1% Error'});
myfigure(6) = openfig('0perc.fig');
legend({'0% Error'});
L2 = findobj(1,'-property','Ydata');
L3 = findobj(2,'-property','Ydata');
L4 = findobj(3,'-property','Ydata');
L5 = findobj(4,'-property','Ydata');
L6 = findobj(5,'-property','Ydata');
L7 = findobj(6,'-property','Ydata');
h1 = set(L2, 'Color', 'b');
h2 = set(L3, 'Color', 'r');
h3 = set(L4, 'Color', 'y');
h4 = set(L5, 'Color', 'c');
h5 = set(L6, 'Color', 'm');
h6 = set(L7, 'Color', 'g');
copyobj(L2,findobj(1,'type','axes'));
copyobj(L3,findobj(1,'type','axes'));
copyobj(L4,findobj(1,'type','axes'));
copyobj(L5,findobj(1,'type','axes'));
copyobj(L6,findobj(1,'type','axes'));
0 Comments
Answers (1)
Cris LaPierre
on 9 Apr 2021
It might be worth trying to specify a target for your legend commands using the syntax
So for example,
legend(myfigure(2),'0.8% Error');
If that doesn't work, consider zipping at least a couple of your figures and attaching that to your post using the paperclip icon.
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!