Inserting Confusion Matrix and ROC plot in one figure

조회 수: 2 (최근 30일)
John F
John F 2022년 6월 24일
답변: John F 2022년 6월 25일
I am trying to plot a Confusion Matrix and a ROC plot in one figure but I can't seem to be able to get it to work. I used the solution provided here but it only plots the ROC plot. Here's my code:
% Plot the Confusion Matrix
cm = confusionchart(targets,predictions,...
'ColumnSummary','column-normalized','RowSummary','row-normalized',...
'Title','PNN Confusion Matrix');
% Plot the ROC plot
classes = ["MyClass 1","MyClass 2","MyClass3","MyClass4","MyClass5","MyClass6"];
roc = plotroc(targets,predictions);
tmp = get(roc,'Children');
lgnd = tmp(2); % Get the ROC plot legend
lgnd.String = cellstr(classes);
% Modified MathWorks Support Team code
figure(3)
ax = zeros(2,1);
for i = 1:2
ax(i)=subplot(2,1,i);
end
for i = 1:2
figure(i)
h = get(gcf,'Children');
newh = copyobj(h,3);
for j = 1:length(newh)
posnewh = get(newh(j),'Position');
possub = get(ax(i),'Position');
set(newh(j),'Position',...
[posnewh(1) possub(2) posnewh(3) possub(4)])
end
delete(ax(i));
end
figure(3)
The plots work correctly if plotted individually but not together.

채택된 답변

John F
John F 2022년 6월 25일
This is the solution I found
% Plot the Confusion Matrix
hold off
f = figure(1);
cm = confusionchart(targets,predictions,...
'ColumnSummary','column-normalized','RowSummary','row-normalized',...
'Title','PNN Confusion Matrix','Parent',f);
% Plot the ROC plot
classes = ["MyClass 1","MyClass 2","MyClass3","MyClass4","MyClass5","MyClass6"];
figure(2)
roc = plotroc(targets,predictions);
tmp = get(roc,'Children');
lgnd = tmp(2);
lgnd.String = cellstr(classes);
figure(3)
ax = zeros(2,1);
for i = 1:2
ax(i)=subplot(1,2,i);
end
% Modified MathWorks Support Team code
for i = 1:2
figure(i)
h = get(gcf,'Children');
newh = copyobj(h,3);
for j = 1:length(newh)
%posnewh = get(newh(j),'Position');
possub = get(ax(i),'Position');
set(newh(j),'Position',...
[possub(1) possub(2) possub(3) possub(4)])
end
delete(ax(i));
end
close([f roc])
ft = figure(3);
tmp = get (ft,'Children');
lgnd = tmp(2);
lgnd.Location = 'best';

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by