How do you include 0's in confusionchart?

6 views (last 30 days)
April Aralar
April Aralar on 12 Jan 2023
Answered: Hitesh on 6 Mar 2025
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 Comments
April Aralar
April Aralar on 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 on 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!

Sign in to comment.

Answers (1)

Hitesh
Hitesh on 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!