Legend on graph not displaying correct labels
조회 수: 12 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Cris LaPierre
2021년 4월 9일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!