The legend does not show the right marker:

조회 수: 27 (최근 30일)
Jacob Assayag
Jacob Assayag 2021년 4월 6일
댓글: Jacob Assayag 2021년 4월 6일
Im trying to plot a graph with multiple plots on it and the legend is off:
i used :
orangeColor=[0.9290 0.6940 0.1250];
blueColor=[0 0.4470 0.7410];
scatter(XTestSet(:,2),YTestSet,[],orangeColor,'filled',"o");
scatter(XTrainSet(:,2),YTrainSet,[],blueColor,'o');
hold on;
polynum1(:,i)=PolyPredictorTest;
end
for k=1:4:9
plot(Xsorttestpoly,polynum1(:,k),"LineWidth",1.5);
end
legend('Train Data','Test Data','N=1','N=5','N=9')
hold off;
Thank you!

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 6일
When using legend it is always preferable to use an array of handles returned from the plotting functions. Try something like:
orangeColor=[0.9290 0.6940 0.1250];
blueColor=[0 0.4470 0.7410];
ph1 = scatter(XTestSet(:,2),YTestSet,[],orangeColor,'filled',"o");'
hold on
ph2 = scatter(XTrainSet(:,2),YTrainSet,[],blueColor,'o');
polynum1(:,i) = PolyPredictorTest;
end
for k = 1:4:9
ph3(1+(k-1)/4) = plot(Xsorttestpoly,polynum1(:,k),"LineWidth",1.5);
end
legend([ph1,ph2,ph3],'Train Data','Test Data','N=1','N=5','N=9')
hold off;
HTH

추가 답변 (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