what is the best way of showing legend?

1 次查看(过去 30 天)
could anyone tell me what is the best way of showing legend in this example?
plot(x1,y1,'o-r',-x1,y1,'o-r');hold on;
plot(x2,y2);
%I tried this way:
legend('show');legend('plotx1y1','','plotx2y2');
% but it does not look good!
I appreciate any help!

采纳的回答

dpb
dpb 2022-8-17
You don't explain what you don't like nor show us what you got and we don't have your data, so we're flying blind here, but I'll guess
plot([-x1(:);x1(:)],[y1(:);y1(:)],'o-r');
hold on;
plot(x2,y2);
legend('plotx1y1','plotx2y2');
or
hL=gobjects(3,1); % preallocate for line handles to come
hL=plot(x1,y1,'o-r',-x1,y1,'o-r'); % first two
hold on;
hL(3)=plot(x2,y2); % and third...
legend(hL([1 3]),'plotx1y1','plotx2y2'); % label the desired ones
or
plot(x1,y1,'o-r','DisplayName','plotx1y1','Annotation','on'); % first, use legend
hold on;
plot(-x1,y1,'o-r','Annotation','off'); % no legend on second
plot(x2,y2,'DisplayName','plotx2y2','Annotation','on'); % show third
legend % turn the legend on

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by