The legend does not show the right marker:

26 visualizaciones (últimos 30 días)
Jacob Assayag
Jacob Assayag el 6 de Abr. de 2021
Comentada: Jacob Assayag el 6 de Abr. de 2021
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!

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 6 de Abr. de 2021
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

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by