How do you include 0's in confusionchart?

Is there a way to display 0's in a confusionchart?
i have searched through MATLAB document for confusionchart to no avail, and a Google search brought me to the first question but no other answers. :(
I am attaching the code that I used to get the confusion chart, and any guidance will be appreciated! Otherwise manually adding a 0's in power point will be my option. Thanks!
path = 'X:\GC_Experiments2\MelioData\Melio_Clean_6_predictions.csv';
data = readtable(path);
group1 = table2array(data(:,2));
group2 = table2array(data(:,3));
D = unique(group1);
labels = [D(1,1),D(2,1),D(3,1),D(4,1),D(5,1),D(6,1),D(7,1),D(8,1),D(9,1)];
C = confusionmat(group1,group2,'Order',labels);
figure;
confusionchart(C,'OffDiagonalColor','b');

4 commentaires

Rik
Rik le 13 Jan 2023
Modifié(e) : Rik le 17 Jan 2023
Please format your code as code and attach your data. That way we can run your exact code and get the same results.
Sangmin
Sangmin le 7 Jan 2025
Did you find the solution?
April Aralar
April Aralar le 7 Jan 2025
Nope! I ended up having to manually add the 0's in Powerpoint which was a little sad
Mike Croucher
Mike Croucher le 9 Jan 2025
I took a look just now and couldn't figure out anything from the documentation so I have raised this with development as an enhancement request. I agree, no one should be manually adding 0's with Powerpoint!

Connectez-vous pour commenter.

 Réponse acceptée

This functionality is now available in MATLAB R2026a. You can get a confusionchart to show zeros using the ZerosVisible property.
g1 = [3 2 2 3 1 1]'; % Known groups
g2 = [4 2 3 NaN 1 1]'; % Predicted groups
C = confusionmat(g1,g2)
C = 4×4
2 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
confusionchart(C,ZerosVisible="on")

Plus de réponses (1)

Hitesh
Hitesh le 6 Mar 2025
Hi April,
I too encountered the similar issue with the "confusionchart", the workaround that worked for me was to use "heatmap". After creating the confusion matrix and display it using a "heatmap".This will ensure that all values, including zeros, are visible.
Kindly refer to the following code:
% Create a heatmap for the confusion matrix
h = heatmap(confMat);
% Use a modified colormap for lighter colors
originalColormap = parula; % Use 'hot', 'parula', or another colormap
lightColormap = 0.5 + 0.5 * originalColormap; % Lighten the colormap
% Apply the lighter colormap
h.Colormap = lightColormap;
% Customize the heatmap appearance
h.ColorbarVisible = 'off';
h.CellLabelColor = 'black'; % Ensure labels are visible
h.CellLabelFormat = '%d'; % Display as integers
% Add titles and labels for clarity
h.Title = 'Confusion Matrix';
h.XLabel = 'Predicted Class';
h.YLabel = 'True Class';
For more information regarding the "heatmap", kindly refer to the following MATLAB documenation:

Community Treasure Hunt

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

Start Hunting!

Translated by