Effacer les filtres
Effacer les filtres

Adding Legend to Perfcurve

2 vues (au cours des 30 derniers jours)
MByk
MByk le 9 Sep 2018
Modifié(e) : MByk le 10 Sep 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 commentaire
madhan ravi
madhan ravi le 9 Sep 2018
can you provide all the datas?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 9 Sep 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 commentaire
MByk
MByk le 10 Sep 2018
Modifié(e) : MByk le 10 Sep 2018
Thank you both for answering.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by