Adding Legend to Perfcurve

1 visualización (últimos 30 días)
MByk
MByk el 9 de Sept. de 2018
Editada: MByk el 10 de Sept. de 2018
I am plotting "perfcurve" but class 2 is shown as a green circle in the legend. How can fix it? Thanks for the help.
for m = 1:nClasses
[FPR,TPR,~,AUC,OOP] = perfcurve(Y,score(:,m),m,'XCrit','fpr');
Legend{m} = strcat(['Class ',num2str(m),' AUC ',num2str(AUC)]);
plot(FPR,TPR,OOP(1),OOP(2),'go','LineWidth',1,'MarkerSize',6)
xlabel('FPR','FontSize',10,'FontWeight','Bold');
ylabel('TPR','FontSize',10,'FontWeight','Bold');
grid on;
hold on;
end
legend(Legend,'FontSize',8,'FontWeight','Bold','Location','Southeast')
hold off;
  1 comentario
madhan ravi
madhan ravi el 9 de Sept. de 2018
can you provide all the datas?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Sept. de 2018
This is expected from your code. You have
plot(FPR,TPR,OOP(1),OOP(2),'go','LineWidth',1,'MarkerSize',6)
The first pair of coordinates FPR,TPR does not have a linespec after it, so it will be plotted with the default color. The second pair of coordinates OOP(1),OOP(2) has 'go' after it, so that point will be plotted as a green circle. These create two different "primitive line" objects.
You appear to have three classes, so you are executing the plot() twice. Each time you are creating two primitive line objects
When you then legend() with three strings passed in as Legend, MATLAB takes the first three graphics objects as being the ones to place the legends for -- so the first line, then the first green marker, then the line of the second class. And that is what will appear in your legend.
The solution is:
for m = 1:nClasses
[FPR,TPR,~,AUC,OOP] = perfcurve(Y,score(:,m),m,'XCrit','fpr');
Legend{m} = strcat(['Class ',num2str(m),' AUC ',num2str(AUC)]);
plothandles(:,m) = plot(FPR,TPR,OOP(1),OOP(2),'go','LineWidth',1,'MarkerSize',6);
xlabel('FPR','FontSize',10,'FontWeight','Bold');
ylabel('TPR','FontSize',10,'FontWeight','Bold');
grid on;
hold on;
end
legend(plothandles(1,:), Legend,'FontSize',8,'FontWeight','Bold','Location','Southeast')
hold off;
  1 comentario
MByk
MByk el 10 de Sept. de 2018
Editada: MByk el 10 de Sept. de 2018
Thank you both for answering.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by