How do I access the axes handles of a confusion matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/213396/image.jpeg)
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!
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!