Adding Legend to Perfcurve
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
MByk
el 9 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
Respuesta aceptada
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!