필터 지우기
필터 지우기

Adding Legend to Perfcurve

조회 수: 2 (최근 30일)
MByk
MByk 2018년 9월 9일
편집: MByk 2018년 9월 10일
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
madhan ravi
madhan ravi 2018년 9월 9일
can you provide all the datas?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 9일
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
MByk
MByk 2018년 9월 10일
편집: MByk 2018년 9월 10일
Thank you both for answering.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by