필터 지우기
필터 지우기

How do I access the axes handles of a confusion matrix?

조회 수: 4 (최근 30일)
pldr-bny
pldr-bny 2019년 4월 11일
댓글: Adam Danz 2019년 4월 15일
Hi there, I am trying to plot something similar to the photo below (although clearly with a smaller font size), with the same axes labels (actual/predicted) and axes tick marks (class numbers):
The code I was implementing to generate the plot throws the following error when attempting to access the XLabel property of the Xaxis: 'No appropriate method, property or field'XLabel' for class 'matlab.ui.container.Menu'.
I think I am accessing the axes fields incorrectly using the following code:
figure(1)
plotconfusion(known_labels, predicted_labels)
fh = gcf;
ax = gca;
ax.FontSize = 8;
set(findobj(ax,'type','test'),'fontsize',3);
ah = fh.Children(2);
ah.XLabel.String = 'Actual';
ah.YLabel.String = 'Predicted';
ax.XTickLabel = class_labels;
ax.YTickLabel = class_labels;
title('Confusion Matrix 1', 'Fontsize',14)
set(gcf,'color','w');
hold off
Any help with how to do this correctly would be greatly appreciated. Thanks!

답변 (1개)

Adam Danz
Adam Danz 2019년 4월 11일
편집: Adam Danz 2019년 4월 11일
You're accessing the XTickLabel field correctly but you're trying to enter a 'matlab.ui.container.Menu' object rather than a cell array of strings (or a numeric vector).
The XTickLabel controls the x tick mark labes. Look at the value of "class_labels" in your code (we don't have access to this). It doesn't specify tick labels.
Also, you could improve how you're getting the axis handle. The plotconfusion() function outputs the figure handle.
fh = plotconfusion(known_labels, predicted_labels);
fh.Children(2).XLabel.String = 'Actual';
fh.Children(2).YLabel.String = 'Predicted';
% Examples of x tick labels (for a matrix with 11 columns)
fh.Children(2).XTickLabel = {'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k'};
fh.Children(2).XTickLabel = 200:210
  댓글 수: 6
pldr-bny
pldr-bny 2019년 4월 12일
Calling class(class_labels) returns 'cell' and the variable description is 71x1 cell array.
I tried converting class_labels to a vector of doubles but I am still getting the original error. When I pass {"01", "02" .....} directly to the XTickLabel object, again I get the original error.
Could there be anything else going wrong here?
Adam Danz
Adam Danz 2019년 4월 15일
This line below (from your penultimate comment) doesn't appear to be a cell array. Could you copy-paste the variable from the command window? How was this variable created? Maybe you could attach that variable to an mat file so I could look at it. The format of this line below is strange to me.
class_labels = {"01"} {"02"} {"03"} ...

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by