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
  1 件のコメント
Jacob Assayag
Jacob Assayag 2021 年 4 月 6 日
thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by